作业帮 > 综合 > 作业

pascal 读入一串数字,以句号结束,请统计其中‘0’到‘9’的各个数字的个数.

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/06 20:47:09
pascal 读入一串数字,以句号结束,请统计其中‘0’到‘9’的各个数字的个数.
读入一串数字,以句号结束,请统计其中‘0’到‘9’的各个数字的个数.如输入:91254782354987012345978.输出:0:1 1:2 2:3 3:2 4:3 5:3 7:3 8:3 9:3
var s:string; a:array [0..9] of longint; i:longint; begin readln(s); fillchar(a,sizeof(a),0); for i:=1 to length(s)-1 do inc(a[ord(s[i])-48]); for i:=0 to 8 do if a[i]0 then write(i,':',a[i],' '); if a[9]0 then write('9:',a[9]); writeln; end.