标题:这个为什么总是WA?牛人求帮助
只看楼主
枫叶无痕
Rank: 2
等 级:论坛游民
帖 子:80
专家分:30
注 册:2011-2-10
结帖率:73.91%
已结贴  问题点数:20 回复次数:2 
这个为什么总是WA?牛人求帮助
Problem A:Delete Number

Time 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");
        }
    }
}
搜索更多相关主题的帖子: example Memory number 
2011-07-04 20:17
落叶深蓝色
Rank: 8Rank: 8
来 自:山东
等 级:蝙蝠侠
帖 子:319
专家分:807
注 册:2010-12-8
得分:10 
2011-07-04 22:32
ansic
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:恍惚窈冥
等 级:城市猎人
帖 子:1543
专家分:5367
注 册:2011-2-15
得分:10 
看不懂E文。。。

善人者,不善人之师;不善人者,善人之资。不贵其师,不爱其资,虽智大迷。
2011-07-04 22:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-344700-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.155953 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved