一道oj上的题目,麻烦哪位大虾帮忙做一下,万分感谢。

[复制链接]
查看11 | 回复3 | 2011-5-16 10:45:24 | 显示全部楼层 |阅读模式
sort

TimeLimit:1000MSMemoryLimit:65536K
TotalSubmit:1173Accepted:224

Description

Givennintegernumbers,youshouldselectthemnumbersofthebiggeronesandoutputthemfrombigonetosmallone.

Input

Theinputfilecontainsmanytestcases.
Eachcasehas2lines.
Thefirstlineconsistsof2integernumbernandm(0n,m1000000).
Thenextlinehasnnumbers,andallnumbersbetween-500000and-500000.

Output

Foreachcase,youshouldoutputthemintegernumbers,orderbydescent.

SampleInput


53
3-3592213-644
SampleOutput


213923
Hint

Ifn=10m=3
andthe10numbersare:
109108765412
youshouldoutput:
10109

在自学c语言,想参加acm,以前遇到类似的问题都是小数值的,不像这个,有1000000这么大,老是wa,能否跟我讲一下做这种类型的题目应该注意些什么。
回复

使用道具 举报

千问 | 2011-5-16 10:45:24 | 显示全部楼层
可以用built-in的qsort

#includeiostream
#includecstdlib
usingnamespacestd;

intarray[1000000];

intcomp(constvoid*a,constvoid*b)
{
        return*((int*)b)-*((int*)a);
}

intmain()
{
        intm,n;
        while(scanf(\"%d%d\",in;i)
                {
                        scanf(\"%d\",arrayi);
                }
                qsort(array,n,sizeof(int),comp);
                for(inti=0;im;i)
                {
                        if(i)putchar(\'\');
                        printf(\"%d\",array);
                }
                putchar(10);
        }
}









<h4class=\"ask\">追问


oj上显示是TimeLimitExceed诶,还有能否用c啊,我c还不会的,麻烦了。
回复

使用道具 举报

千问 | 2011-5-16 10:45:24 | 显示全部楼层
麻烦给个OJ地址给我,好么
回复

使用道具 举报

千问 | 2011-5-16 10:45:24 | 显示全部楼层
<ahref=\"http://acmpj.zstu.edu.cn/JudgeOnline\"target=\"_blank\">http://acmpj.zstu.edu.cn/JudgeOnline</a>,题目是16页的2505sort,谢谢了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行