寻找最大数
时间限制:1000 ms | 内存限制:65535 KB
难度:2
- 描述
-
请在整数 n 中删除m个数字, 使得余下的数字按原次序组成的新数最大,
比如当n=92081346718538,m=10时,则新的最大数是9888
- 输入
- 第一行输入一个正整数T,表示有T组测试数据
每组测试数据占一行,每行有两个数n,m(n可能是一个很大的整数,但其位数不超过100位,并且保证数据首位非0,m小于整数n的位数) - 输出
- 每组测试数据的输出占一行,输出剩余的数字按原次序组成的最大新数
- 样例输入
-
2 92081346718538 10 1008908 5
- 样例输出
-
9888 98
#include<stdio.h> #include<string.h> int main() { int n,m,j,i,sum,l,t,k; char a[110]; scanf("%d",&n); while(n--) { getchar(); scanf("%s",a); l=strlen(a); scanf("%d",&m); k=0;t=0; while(m!=(l)) { k=a[t]; for(i=t+1;i<=m;i++) //此循环判断这组数中较大的 { //如果k小于某个数则将此数赋值给k if(k<a[i]) { k=a[i]; t=i; //记录下此时这个数的位置 } } printf("%c",k); t=t+1; m++; } printf(" "); } return 0; }