提交时间:2022-10-04 11:26:52
运行 ID: 57470
#include<bits/stdc++.h> using namespace std; int t,n; char s[100005]; int main(){ cin>>t; while(t--){ cin>>n>>s; int len=strlen(s),now; now=len; if(len==n)cout<<s<<endl; else if(len<n){ for(int i=0;i<len;i++){ if(s[i]=='w'&&now<n)++now,cout<<"uu"; else if(s[i]=='m'&&now<n)++now,cout<<"nn"; else cout<<s[i]; } puts(""); }else{ for(int i=0;i<len;i++){ int j=i; if(s[j]=='w')while(s[j-1]=='u'&&j)swap(s[j],s[j-1]),--j; if(s[j]=='m')while(s[j-1]=='n'&&j)swap(s[j],s[j-1]),--j; } for(int i=1;i<len;i++){ if(s[i]=='u'&&s[i-1]=='u'&&now>n)s[i]='-',s[i-1]='w',--now; if(s[i]=='n'&&s[i-1]=='n'&&now>n)s[i]='-',s[i-1]='m',--now; } for(int i=0;i<len;i++){ if(s[i]!='-')cout<<s[i]; } puts(""); } } return 0; }