AcWing 1602. 卡住的键盘
原题链接
简单
作者:
巨鹿噜噜噜路
,
2020-05-28 10:13:25
,
所有人可见
,
阅读 681
C++ 代码
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
const int MAX_S = 1010;
unordered_map<char, bool> isGood, vis;
bool isNotPrint[MAX_S];
int main() {
int n;
string str, ans = "";
cin >> n >> str;
int cnt = 1;
int len = str.size();
for (int i = 0; i < len; i++) {
int j = i + 1;
while (j < len && str[i] == str[j]) j++;
if((j - i) % n != 0) isGood[str[i]] = true;
i = j - 1;
}
for (int i = 0; i < len; i++) {
if (isGood[str[i]] == false) {
if (!vis[str[i]]) {
ans += str[i];
vis[str[i]] = true;
}
for (int j = 0; j < n - 1; j++) {
isNotPrint[j + i] = true;
}
i = i + n - 1;
}
}
printf("%s\n", ans.c_str());
for (int i = 0; i < len; i++) {
if (isNotPrint[i]) continue;
printf("%c", str[i]);
}
return 0;
}