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

运行 ID: 57445

#include<bits/stdc++.h> using namespace std; bool me[200005]; char kun[200005]; int n,t,len,cnt; string s; int main(){ // freopen("J2.in","r",stdin); // freopen("J2.out","w",stdout); scanf("%d",&t); while(t--){ scanf("%d",&n); cin>>s; len=s.length(); if(len==n) cout<<s<<endl; else{ cnt=0; memset(me,0,sizeof(me)); for(int i=0;i<len;i++){ cnt++; if(s[i]=='m'){ kun[cnt+1]=kun[cnt]='n'; cnt++; } else if(s[i]=='w'){ kun[cnt+1]=kun[cnt]='u'; cnt++; } else kun[cnt]=s[i]; } int wzj=cnt; for(int i=1;i<=cnt;i++){ if(!me[i]){ if(wzj>n){ if(kun[i]==kun[i+1]&&kun[i]=='u'){ printf("w"); me[i+1]=1; wzj--; } else if(kun[i]==kun[i+1]&&kun[i]=='n'){ printf("m"); me[i+1]=1; wzj--; } else printf("%c",kun[i]); } else printf("%c",kun[i]); } } printf("\n"); } } return 0; }