Description
工商部门查获了有N个人正在贩卖注水猪肉,现在要你对这N个人的注水猪肉的数量从大到小的排序,并且算出这N个人的注水猪肉总和(单位为…..斤)…我们姑且称这些贩卖者为”猪王”吧..
Input
输入的第一行是一个1到1000的整数N,表示总共有N位猪王参加了争霸赛。以下依次给出每位猪王的描述,一位猪王的描述占据两行,第一行为一个仅由小写字母组成的长度不超过13的字符串,代表这个猪王的名字,第二行一个整数(非负数,<10^2000),代表这个猪王的注水猪肉总斤数。注意,这个整数的首位没有不必要的0。所有猪王贩卖的注水猪肉数量的总长度不会超过2000。
Output
依次输出按照注水猪肉多少从大到小排好序的各位贩卖者的名字,每个名字占据单独的一行。不能有任何多余的字符。若几个名字的注水猪肉数相同,则按照名字的字典顺序先后排列。(名字长度<=13且均为大写字母),在N+1行输出所有猪王贩卖注水猪肉的数量的总和(输出最后490位)
Sample Input
5
ABC
123
ABCD
1234
ABCDE
12345
ABCDEF
123456
ABCDEFG
1234567
Sample Output
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001371725
分析
排序+高精
程序:
const
maxn=2050;
var
n,i,j,l1,l2:longint;
a,b:array[0..maxn]of ansistring;
c:array[0..maxn]of longint;
procedure jia(k:longint);
var
i,j:longint;
begin
for i:=length(b[k]) downto 1 do
inc(c[maxn-length(b[k])+i],ord(b[k][i])-48);
for i:=maxn downto maxn-500 do
begin
c[i-1]:=c[i-1]+c[i] div 10;
c[i]:=c[i] mod 10;
end;
end;
begin
readln(n);
for i:=1 to n do
begin
readln(a[i]);
readln(b[i]);
end;
for i:=1 to n do
jia(i);
for i:=1 to n-1 do
for j:=i+1 to n do
begin
l1:=length(b[i]);
l2:=length(b[j]);
if (l1<l2)or((l1=l2)and(b[i]<b[j]))or((l1=l2)and(b[i]=b[j])and(a[i]>a[j])) then
begin
b[0]:=b[i];b[i]:=b[j];b[j]:=b[0];
a[0]:=a[i];a[i]:=a[j];a[j]:=a[0];
end;
end;
for i:=1 to n do
writeln(a[i]);
for i:=maxn-490+1 to maxn do
write(c[i]);
end.