PAT (Advanced Level) Practice 1112 Stucked Keyboard (20 分)
阿新 • • 發佈:2018-12-07
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e3+5;
char s[N];
int in[N],vis[N];
int main()
{
int k;scanf("%d",&k);
scanf("%s",s);
int len=strlen(s),p=0;
for(int i=0;i<len;i=p)
{
while(p<len&& s[p]==s[i]) p++;
if((p-i)%k!=0) vis[s[i]]=1;
}
for(int i=0;i<len;i++)
if(!vis[s[i]]&&!in[s[i]])
printf("%c",s[i]),in[s[i]]=1;
puts("");
p=0;
for(int i=0;i<len;i=p)
{
if(vis[s[i]])
{
printf("%c",s[i]);
p++ ;
continue;
}
while(p<len&&s[p]==s[i]) p++;
for(int j=1;j<=(p-i)/k;j++)
printf("%c",s[i]);
}
puts("");
return 0;
}