这个为什么总是WA?牛人求帮助
Problem A:Delete NumberTime Limit:1000MS Memory Limit:65536K
Total Submit:820 Accepted:149
Description
Given 2 integer number n and m. You can delete m digits from the number n, then number n changes to a new number n1. Tell me how to delete the number, you can get the smallest one.
For example,
m: 1 n: 1456
n1 may be 145, 156, 146, 456
the smallest one is 145. Then n1 should be 145.
Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case consists of one single line containing two integer number m(1 <= m <= 1000), and n(1 <= n < 101000).
Output
Your program must output a single line for each test case. The line should contain the number n1.
Sample Input
1
1 1456
Sample Output
145
Hint
if the number is 000345 you should output 345
代码:
#include<stdio.h>
main()
{
int t,m,i,j,f,c,s;
long str[10],k;
char n;
while(scanf("%d",&t)!=EOF)
{
for(i=1;i<=t;i++)
{
for(j=0;j<=9;j++)
{
str[j]=0;
}
scanf("%d",&m);
getchar();
while(scanf("%c",&n))
{
if(n=='\n')
{
break;
}
else
{
s=n-'0';
str[s]++;
}
}
c=1;
for(j=9;j>=0;j--)
{
for(;c<=m;c++)
{
if(str[j]==0)
break;
str[j]=str[j]-1;
}
}
for(j=1;j<=9;j++)
{
for(k=1;k<=str[j];k++)
{
printf("%d",j);
}
}
printf("\n");
}
}
}