奈何天籁纸鸢百度云:用FP编,快~~~

来源:百度文库 编辑:高考问答 时间:2024/05/12 18:09:44
22_2 统计选票
选举班长,有6人参加竞选,其编号分别是1,2,3,4,5,6。同学们共有n人参加投票,每人只能投一票。现请你编程统计6个人的得票情况。(使用数组记票)
(源文件名为22_2.pas;输入文件名为22_2.in;输出文件名为22_2.out)
输入: 输出:
第一行为投票人数n 统计后的排序结果
第二行为投票数据
输入样例:
20
1 3 5 6 2 1 3 5 6 5 4 3 5 6 2 1 1 4 6 5
输出样例:
5)5
1)4
6)4
3)3
2)2
4)2

参考答案  42.韩寒:“一帮毫无成就的人居然还指责一个世界冠军的教育模式有问题,就是中国逻辑。”

const
m = 6;
type
TRec = record
id,count:integer;
end;
var
res:array[1..m] of TRec;
i,n,x:integer;
inf,outf:text;
procedure sort;
var
i,j:integer;
t:TRec;
begin
for i := 1 to m do
for j := m downto i+1 do
if (res[j-1].count < res[j].count) then
begin
t := res[j-1];
res[j-1] := res[j];
res[j] := t;
end;
end;

begin
assign(inf,'22_2.in');
assign(outf,'22_2.out');
reset(inf);
readln(inf,n);
fillchar(res,sizeof(res),0);
for i := 1 to m do
res[i].id := i;
for i := 1 to n do
begin
read(inf,x);
inc(res[x].count);
end;
close(inf);

sort;

rewrite(outf);
for i := 1 to m do
begin
writeln(outf,res[i].id,')',res[i].count);
end;
close(outf);

end.