处理起来稍微有点麻烦
#include<bits/stdc++.h>
using namespace std;
int main() {
int k;
string s="";
cin>>k>>s;
int hashTable[128]={0};
for (int i = 0; i < s.size();) {
int j=i+1;
while (j<s.size() and s[j]==s[i])
j++;
if (hashTable[s[i]]>=0)
hashTable[s[i]]=(j-i)%k==0?1:-1;
i=j;
}
string outPut="";
bool hashOut[128]={false};
for (int i = 0; i < s.size(); ) {
outPut+=s[i];
if (hashTable[s[i]]>0){
if (!hashOut[s[i]]){
printf("%c",s[i]);
hashOut[s[i]]= true;
}
i+=k;
}
else if (hashTable[s[i]]<0){
i++;
}
}
cout<<endl<<outPut;
}