pascal问题:选票统计(具体要求如下↓)

来源:百度知道 编辑:UC知道 时间:2024/05/21 16:16:57
pascal问题:选票统计:有a,b,c,d四位候选人,n位投票人,统计时,a,b,c,d以外的字符为弃权。要求打印出候选人和所得票数。

var s,a,n,b,c,d:integer;
t:char;
procedure p(g:char;h,j,k,l:integer;var y,u,i,o:integer);
begin
case g of
'a','A':y:=h+1;
'b','B':u:=j+1;
'c','C':i:=k+1;
'd','D':o:=l+1;
end;
end;
begin
write('n='); readln(n);
a:=0; b:=0; c:=0; d:=0;
for s:=1 to n do begin readln(t); p(t,a,b,c,d,a,b,c,d); end;
writeln('a=',a,' b=',b,' c=',c,' d=',d);
readln;
end.

program tongji;
var i,s,n:integer;
t:char;
begin
readln(n);
for i:=1 to n do
begin
readln(t);
if t='a' then inc(a)
else if t='b' then inc(b)
else if t='c' then inc(c)
else if t='d' then inc(d)
else inc(s);
end;
writeln('A:',a,' ','B:',b,