提交时间:2022-10-04 11:24:35

运行 ID: 57447

#include<bits/stdc++.h> using namespace std; const int N =1e6+10; string s; bool vis[N]; void PUT(int now,int x) { for(int i=now;i<x;i++) if(vis[i]==false) cout<<s[i]; } void Slove(int n,int k) { if(n>k) { int prep=n-k; for(int i=0;i<k;i++) { //cout<<prep<<endl; //cout<<s[i]<<" "; if(prep==0) { PUT(i,k); break; } if(s[i]=='w') { cout<<"uu"; prep--; } else if(s[i]=='m') { cout<<"nn"; prep--; } else cout<<s[i]; } } else if(n==k) { cout<<s; cout<<endl; return ; } else { int prep=k-n; for(int i=0;i<k;i++) { if(prep==0) { PUT(i,k); break; } if(s[i]=='u'&&vis[i]==false) { vis[i]=true; for(int j=i+1;j<k;j++) if(s[j]=='u'&&vis[j]==false) { vis[j]==true,cout<<"w"; break; } } else if(s[i]=='n'&&vis[i]==false) { vis[i]=true; for(int j=i+1;j<k;j++) if(s[j]=='n'&&vis[j]==false) { vis[j]==true,cout<<"m"; break; } } else cout<<s[i]; } } } int main() { //freopen("J2.in","r",stdin); //freopen("J2.out","w",stdout); int t; cin>>t; while(t--) { memset(vis,false,sizeof(vis)); int p; cin>>p; cin>>s; int k=s.length(); Slove(p,k); cout<<endl; } return 0; }