标签:
请在整数 n 中删除m个数字, 使得余下的数字按原次序组成的新数最大,
比如当n=92081346718538,m=10时,则新的最大数是9888
2 92081346718538 10 1008908 5
9888 98题意:寻找局部最大解;
1 #include<stdio.h> 2 #include<string.h> 3 char n[110]; 4 void find(int x){ 5 int t=strlen(n),y,temp=0,i; 6 char max; 7 y=t-x; 8 while(y--){max=‘0‘; 9 for(i=temp;i<t-y;i++){ 10 if(n[i]>max)max=n[i],temp=i+1; 11 } 12 printf("%c",max); 13 } 14 } 15 int main(){ 16 int T,m; 17 scanf("%d",&T); 18 while(T--){ 19 scanf("%s%d",n,&m); 20 find(m);puts(""); 21 } 22 return 0; 23 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4691724.html