結果

問題 No.342 一番ワロタww
ユーザー dgd1724dgd1724
提出日時 2016-10-30 11:04:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,756 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 149,428 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-16 11:15:40
合計ジャッジ時間 2,742 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

//const static double	de_PI	= 3.14159265358979323846;
//const static int	de_MOD	= 1000000007;
//const static int	de_MAX	= 999999999;
//const static int	de_MIN = -999999999;

inline void UTF8_to_CodePoint(const std::string *str, std::vector<int> &result) {

	std::string S = *str;
	unsigned int i = 0;
	unsigned char c = 0;
	while (i < S.size()) {
		c = S[i];
		if (0 <= c && c < 128) {
			result.push_back(S[i]);
			i += 1;
		}
		else if (194 <= c && c < 224) {
			result.push_back(unsigned(S[i] & 0x1F) << 6 | S[i + 1] & 0x3F);
			i += 2;
		}
		else if (224 <= c && c < 240) {
			result.push_back(unsigned(S[i] & 0x0F) << 12 | unsigned(S[i + 1] & 0x3F) << 6 | S[i + 2] & 0x3F);
			i += 3;
		}
		else {
			result.push_back(unsigned(S[i] & 0x07) << 18 | unsigned(S[i + 1] & 0x3F) << 12 | unsigned(S[i + 2] & 0x3F) << 6 | S[i + 3] & 0x3F);
			i += 4;
		}
	}
}

inline std::string CodePoint_to_UTF8(unsigned int code) {

	if (code < 128) {			//1bite文字 = 有効7bit = 128未満
		return std::string({ static_cast<char>(code),'\0' });
	}
	else if (code < 2048) {		//2bite文字 = 有効11bit = 2048未満
		char bite1 = static_cast<char>(code >> 6 | 0xC0);
		char bite2 = static_cast<char>((code & 0x3F) | 0x80);
		return std::string({ bite1, bite2,'\0' });
	}
	else if (code < 65536) {	//3bite文字 = 有効16bit = 65536未満
		char bite1 = static_cast<char>(code >> 12 | 0xE0);
		char bite2 = static_cast<char>((code >> 6 & 0x3F) | 0x80);
		char bite3 = static_cast<char>((code & 0x3F) | 0x80);
		return std::string({ bite1,bite2,bite3,'\0' });
	}
	else {	//4bite文字
		char bite1 = static_cast<char>(code >> 18 | 0xF0);
		char bite2 = static_cast<char>((code >> 12 & 0x3F) | 0x80);
		char bite3 = static_cast<char>((code >>6 & 0x3F) | 0x80);
		char bite4 = static_cast<char>((code & 0x3F) | 0x80);
		return std::string({ bite1,bite2,bite3,bite4,'\0' });
	}
}

/*
1バイト文字なら、アスキーコードと一致する範囲なので、
string型に変換してそのまま返すだけ

2バイト文字の場合、構成を1バイト目が(110x xxxx)、2バイト目が(10xx xxxx)になるように
以下の手順で分割、整形する。

1.6ビット右シフト = 元の全11bit中、先頭の5bitを取り出す
2.0xC0(1100 0000)とOR演算 = 取り出した5bitの先頭に情報bitである110を付加する
3.0x3F(0011 1111)とAND演算 = 元の全11bit中、残りの6bitを取り出す
4.0x80(1000 0000)とOR演算 = 取り出した6bitの先頭に情報bitである10を付加する

1,2が1バイト目、3,4が2バイト目を整形している処理。
最後に1バイト目と2バイト目を連結してstring型に変換して返す。
string型への変換は配列の末尾にヌル文字('\0')を付加する。

3バイト文字以降も考え方は同じ。

*/

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());	

	std::string S;
	std::cin >> S;
	std::vector<int> code;
	UTF8_to_CodePoint(&S, code);

	int A[100][100] = {};
	int B[100] = {};
	int max = 0, score = 0;
	unsigned int i = 0, j = 0, k = 0;

	while (code[i] == 65367) { i++; }

	while (i < code.size()) {
		if (code[i] != 65367) {
			if (score != 0) {
				B[j] = score;
				j++;
				if (score > max) { max = score; }
				score = 0;
			}
			A[j][k] = code[i];
			k++;
		}
		else {
			if (k != 0) { k = 0; }
			score++;
		}
		i++;
	}
	if (score != 0) { 
		B[j] = score;
		if (score > max) { max = score; }
	}

	if (B[0] == 0 || B[0] == static_cast<int>(code.size())) {
		std::cout << "" << std::endl;
		return 0;
	}

	for (i = 0; B[i] != 0; i++) {
		if (B[i] == max) {
			for (j = 0; A[i][j] != 0; j++) {
				std::cout << CodePoint_to_UTF8(A[i][j]);
			}
			std::cout << std::endl;
		}
	}

}

0