#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<set>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int k;
cin>>k;
string a;
cin>>a;
a=a+"##";
map<char,bool> cnt;
map<char,bool> hash;
for(int i=0;i<a.length()-2;i++){
string temp1,temp2;
for(int j=i;j<i+k;j++){
temp1=temp1+a[j];
temp2=temp2+a[i];
}
if(temp1==temp2){
cnt[a[i]]=0;
i=i+k-1;
}else{
cnt[a[i]]=1;
}
}
string ss;
vector<char> t;
for(int i=0;i<a.length()-2;i++){
if(cnt[a[i]]==false){
if(hash[a[i]]==0){
t.push_back(a[i]);
hash[a[i]]=true;
}
ss=ss+a[i];
i=i+k-1;
}else{
ss=ss+a[i];
}
}
for(int i=0;i<t.size();i++){
cout<<t[i];
}
cout<<endl;
cout<<ss<<endl;
return 0;
}
道理上为了避免访问越界,应该加上k-1个“#”,但是为毛上面加两个就过了??而下面加上k-1个却有两个测试点过不了??
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<set>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int k;
cin>>k;
string a;
cin>>a;
for(int i=0;i<k-1;i++)
a=a+"#";
map<char,bool> cnt;
map<char,bool> hash;
for(int i=0;i<a.length()-k+1;i++){
string temp1,temp2;
for(int j=i;j<i+k;j++){
temp1=temp1+a[j];
temp2=temp2+a[i];
}
if(temp1==temp2){
cnt[a[i]]=0;
i=i+k-1;
}else{
cnt[a[i]]=1;
}
}
string ss;
vector<char> t;
for(int i=0;i<a.length()-2;i++){
if(cnt[a[i]]==false){
if(hash[a[i]]==0){
t.push_back(a[i]);
hash[a[i]]=true;
}
ss=ss+a[i];
i=i+k-1;
}else{
ss=ss+a[i];
}
}
for(int i=0;i<t.size();i++){
cout<<t[i];
}
cout<<endl;
cout<<ss<<endl;
return 0;
}