結果

問題 No.342 一番ワロタww
ユーザー alpha_virginisalpha_virginis
提出日時 2016-02-13 00:25:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,849 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 84,280 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 13:16:49
合計ジャッジ時間 1,436 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:78:8: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   78 |   fgets(str, sizeof(str), stdin);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <string.h>

void u8toi(char *str, int *array) {
  int i;
  int n = strlen(str);
  for(i = 0; i < n; ++i) {
    int flag = str[i];
    int mask = ~flag;  
    mask |= (mask >> 1);
    mask |= (mask >> 2);
    mask |= (mask >> 4);
    int res = str[i] & mask;
    while( 0xC0 <= (unsigned char)flag ) {
      i += 1;
      flag <<= 1;
      res <<= 6;
      res |= str[i] & 0x3F; 
    }
    *array++ = res;
  }
  *array++ = 0;
}

class Tclass {
public:
  Tclass();
  Tclass(int a, std::vector<int> b) {
    data = std::pair<int, std::vector<int>>(a, b);
  }
  std::pair<int, std::vector<int>> data;
};

bool operator < (const Tclass& left, const Tclass& right) {
  return left.data.first < right.data.first;
}

void itou8(int *array, char *str) {
  int i;
  while( *array != 0 ) {
    int c = *array;
    char str2[8];
    int len = 0;
    char c2;
    if( c < 0x80 ) {
      str2[0] = c;
      len = 1;
    }
    else {
      while( c != 0 ) {
        c2 = (c & 0x3f);
        str2[len] = c2;
        len += 1;
        c >>= 6;
      }
    }
    if( len != 1 ) {
      str2[len - 1] |= (((unsigned char)(0xff)) << (8 - len));
      for(i = 0; i < len - 1; ++i) {
        str2[i] |= 0x80;
      }
    }
    for(i = len - 1; i >= 0; --i) {
      *str++ = str2[i];
    }
    array += 1;
  }
  *str++ = 0;
}

int main() {
  char str[1000];
  fgets(str, sizeof(str), stdin);
  str[strlen(str)-1] = '\0';
 
  int str2[1000];
  u8toi(str, str2);
  itou8(str2, str);
  //printf("%s\n", str);

  char t[100] = "w";
  int t2[100];
  u8toi(t, t2);
  int tt = t2[0];

  int temp = 0;
  std::vector<int> ttstr;
  std::vector<Tclass> candi;
  for(int i = 0; ; ++i) {
    //printf(" %d\n", str2[i]); 
    if( str2[i] == 0 ) break;
    if( str2[i] == tt ) {
      temp += 1;
    }
    else {
      if( temp != 0 ) {
        if( ttstr.size() != 0 ) {
          candi.push_back(Tclass(temp, ttstr));
          ttstr.clear();
        }
      }
      ttstr.push_back(str2[i]);
      temp = 0;
    }
  }
  if( temp != 0 ) {
    if( ttstr.size() != 0 ) {
      candi.push_back(Tclass(temp, ttstr));
      ttstr.clear();
    }
  }

  std::stable_sort(candi.begin(), candi.end());
  
  int llen = 0;
  if( candi.size() != 0 ) {
    llen = candi[candi.size()-1].data.first;
  }
  bool flag = true;
  for(int i = 0; i < (int)candi.size(); ++i) {
    if( candi[i].data.first != llen ) continue;
    
    char res[1000];
    int  rest[1000];
    for(int j = 0; j < (int)candi[i].data.second.size(); ++j) {
      rest[j] = candi[i].data.second[j];
    }
    rest[candi[i].data.second.size()] = 0;
    itou8(rest, res);
    if( res[0] != '\0' ) {
      printf("%s\n", res);
      flag = false;
    }
  }
  if( flag ) {
    printf("\n");
  }  
  
  return 0;
}
0