标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2521 Accepted Submission(s): 986
1 #include<cstdio> 2 #include<cstring> 3 #define mem(x,y) memset(x,y,sizeof(x)) 4 const int MAXN=5050; 5 char n[MAXN]; 6 int vis[MAXN]; 7 int main(){ 8 int m,t; 9 while(~scanf("%s%d",n,&m)){ 10 mem(vis,0); 11 t=strlen(n); 12 int r=t-1; 13 for(int i=0;i<m;i++){ 14 int cnt=0; 15 for(int j=0;j<r;j++){ 16 if(vis[j])continue; 17 int x=j+1; 18 while(vis[x])x++;// 19 if(n[j]>n[x]){ 20 vis[j]=1;cnt=1;break; 21 /*比赛时候这样写的,一直wa仍然感觉没错。。。 22 if(n[j]<n[j+1]){ 23 cnt=1; 24 vis[j]=1; 25 n[j]=n[j+1]; 26 break; 27 } 28 */ 29 } 30 } 31 if(!cnt)vis[r--]=1; 32 }int flog=1; 33 for(int i=0;i<t;i++){ 34 if(vis[i])continue; 35 if(flog&&n[i]==‘0‘)continue; 36 flog=0;printf("%c",n[i]); 37 } 38 if(flog)printf("0"); 39 puts(""); 40 } 41 return 0; 42 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4965196.html