用数组,排序与分类的作业。
input
输入文件只有一行,一‘?’借宿的一串字符。
output
输出文件共十行,没行输出俩证书,分别是数字和该数字在字符串中出现的次数多少,按降序排列,期间用一个空格隔开。
输入样例
a28455529A9B9c9762z66ob648y88u85c788805o9?
输出样例
8 8
5 5
9 5
6 4
2 3
4 2
7 2
0 1
1 0
3 0
第1个回答 2011-02-09
程序很简单,仔细看吧:
var
a:array ['0'..'9'] of longint;
b:array ['0'..'9'] of char;
c,i,j,tt:char;
t:longint;
begin
//初始化
for i:='0' to '9' do
b[i]:=i;
//读取字符
read(c);
while c<>'?' do
begin
if (c>='0')and(c<='9') then
inc(a[c]);
read(c);
end;
//冒泡排序
for i:='0' to '8' do
for j:=chr(ord(i)+1) to '9' do
if a[i]<a[j] then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
tt:=b[i];
b[i]:=b[j];
b[j]:=tt;
end;
//输出统计结果
for i:='0' to '9' do
writeln(b[i],' ',a[i]);
end.本回答被提问者采纳
var
a:array ['0'..'9'] of longint;
b:array ['0'..'9'] of char;
c,i,j,tt:char;
t:longint;
begin
//初始化
for i:='0' to '9' do
b[i]:=i;
//读取字符
read(c);
while c<>'?' do
begin
if (c>='0')and(c<='9') then
inc(a[c]);
read(c);
end;
//冒泡排序
for i:='0' to '8' do
for j:=chr(ord(i)+1) to '9' do
if a[i]<a[j] then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
tt:=b[i];
b[i]:=b[j];
b[j]:=tt;
end;
//输出统计结果
for i:='0' to '9' do
writeln(b[i],' ',a[i]);
end.本回答被提问者采纳
第2个回答 2011-02-09
var ch:char;
a:array['0'..'9'] of integer;
begin
while true do
begin
read(ch);
if ch='?' then break;
inc(a[ch]);
end;
for ch:='0' to '9' do
write(a[ch],' ');
end.
a:array['0'..'9'] of integer;
begin
while true do
begin
read(ch);
if ch='?' then break;
inc(a[ch]);
end;
for ch:='0' to '9' do
write(a[ch],' ');
end.
第3个回答 2011-02-08
var
a:array[0..9] of integer;
b:array[0..9] of boolean;
c:char;
i,max,t:integer;
begin
repeat
read(c);
if (c<>'?') and ('0'<c) and (c<'9') then
begin
a[ord(c)-48]:=1+a[ord(c)-48];
end;
until c='?';
for i:=0 to 9 do
begin
b[i]:=true;
end;
max:=0;
t:=0;
repeat
max:=0;
for i:=0 to 9 do
if (a[i]>max) and (b[i]) then max:=a[i];
for i:=0 to 9 do
if a[i]=max then
begin
writeln(i,' ',a[i]);
b[i]:=false;
inc(t);
end;
until t=10;
end.
a:array[0..9] of integer;
b:array[0..9] of boolean;
c:char;
i,max,t:integer;
begin
repeat
read(c);
if (c<>'?') and ('0'<c) and (c<'9') then
begin
a[ord(c)-48]:=1+a[ord(c)-48];
end;
until c='?';
for i:=0 to 9 do
begin
b[i]:=true;
end;
max:=0;
t:=0;
repeat
max:=0;
for i:=0 to 9 do
if (a[i]>max) and (b[i]) then max:=a[i];
for i:=0 to 9 do
if a[i]=max then
begin
writeln(i,' ',a[i]);
b[i]:=false;
inc(t);
end;
until t=10;
end.
第4个回答 2011-02-09
fgf g