結果

問題 No.291 黒い文字列
ユーザー hanorverhanorver
提出日時 2015-10-16 23:40:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,342 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 63,576 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-29 01:59:56
合計ジャッジ時間 1,703 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>

int main() {
	std::string str;
	std::cin >> str;

	for (int i = 0; i < str.length(); i++) {
		if (str[i] != 'K' && str[i] != 'U' && str[i] != 'R' && str[i] != 'O' && str[i] != 'I' && str[i] != '\?') {
			str.erase(str.begin() + i);
			i--;
		}
	}
	
	while(str.size() > 0 && str.front() != 'K' && str.front() != '\?') str.erase(str.begin());
	while (str.size() > 0 && str.back() != 'I' && str.back() != '\?') str.erase(str.begin() + str.size() - 1);

	std::string s = "KUROI";
	int pos = 0;
	std::vector<int> d;
	int ans = 0;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == s[pos]) {
			pos++;
			d.push_back(i);
			if (pos > 4) {
				for (int j = 0; j < 5; j++) {
					str[d[j]] = 'T';
				}
				d.clear();
				i = -1;
				ans++;
				pos = 0;
			}
		}
		if (i == str.length() - 1 && d.size() != 0) {
			i = d.front();
			d.clear();
			pos = 0;
		}
	}

	pos = 0;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == s[pos] || str[i] == '\?') {
			pos++;
			d.push_back(i);
			if (pos > 4) {
				for (int j = 0; j < 5; j++) {
					str[d[j]] = 'T';
				}
				ans++;
				pos = 0;
				i = -1;
				d.clear();
			}
		}
		if (i == str.length() - 1 && d.size() > 0) {
			str[d.front()] = 'T';
			d.clear();
			i = -1;
			pos = 0;
		}
	}

	std::cout << ans << std::endl;
	return 0;
}
0