Original solution provided
Now fixing errors and trace the module
var i, N, x, max: integer;
// Error fix 'a'
a : array[0..9] of integer;
begin
readln(N);
for i:=1 to N do begin
readln(x);
while x > 0 do begin
a[ x mod 10 ] := a[ x mod 10] + 1;
x := x div 10;
end;
end;
for i:=0 to 9 do begin
writeln(i,' has been selected ', a[i] ,' times');
end;
max := 0;
for i := 0 to 9 do
if a[i] > max then max := a[i];
write('max = '); writeln(max);
for i := 9 downto 0 do
// Error fix 'i'
if a[i] = max then writeln( i ,' was submitted ', max ,' times');
end.
[boris@ServerCentOS8 Djobs]$ ./prg27b2411
5
687
374
897
608
711
0 has been selected 1 times
1 has been selected 2 times
2 has been selected 0 times
3 has been selected 1 times
4 has been selected 1 times
5 has been selected 0 times
6 has been selected 2 times
7 has been selected 4 times
8 has been selected 3 times
9 has been selected 1 times
max = 4 7 was submitted 4 times
[boris@ServerCentOS8 Djobs]$ ./prg27b2411
10
5678
4563
789
7654
8576
9073
3201
4563
9876
3454
0 has been selected 2 times
1 has been selected 1 times
2 has been selected 1 times
3 has been selected 5 times
4 has been selected 5 times
5 has been selected 6 times
6 has been selected 6 times
7 has been selected 6 times
8 has been selected 4 times
9 has been selected 3 times
max = 6 7 was submitted 6 times
6 was submitted 6 times
5 was submitted 6 times
[boris@ServerCentOS8 Djobs]$ vi control.txt
[boris@ServerCentOS8 Djobs]$ cat control.txt|grep "6"|wc -l
6
[boris@ServerCentOS8 Djobs]$ cat control.txt|grep "5"|wc -l
6
[boris@ServerCentOS8 Djobs]$ cat control.txt|grep "7"|wc -l
6
Now fixing errors and trace the module
var i, N, x, max: integer;
// Error fix 'a'
a : array[0..9] of integer;
begin
readln(N);
for i:=1 to N do begin
readln(x);
while x > 0 do begin
a[ x mod 10 ] := a[ x mod 10] + 1;
x := x div 10;
end;
end;
for i:=0 to 9 do begin
writeln(i,' has been selected ', a[i] ,' times');
end;
max := 0;
for i := 0 to 9 do
if a[i] > max then max := a[i];
write('max = '); writeln(max);
for i := 9 downto 0 do
// Error fix 'i'
if a[i] = max then writeln( i ,' was submitted ', max ,' times');
end.
[boris@ServerCentOS8 Djobs]$ ./prg27b2411
5
687
374
897
608
711
0 has been selected 1 times
1 has been selected 2 times
2 has been selected 0 times
3 has been selected 1 times
4 has been selected 1 times
5 has been selected 0 times
6 has been selected 2 times
7 has been selected 4 times
8 has been selected 3 times
9 has been selected 1 times
max = 4 7 was submitted 4 times
[boris@ServerCentOS8 Djobs]$ ./prg27b2411
10
5678
4563
789
7654
8576
9073
3201
4563
9876
3454
0 has been selected 2 times
1 has been selected 1 times
2 has been selected 1 times
3 has been selected 5 times
4 has been selected 5 times
5 has been selected 6 times
6 has been selected 6 times
7 has been selected 6 times
8 has been selected 4 times
9 has been selected 3 times
max = 6 7 was submitted 6 times
6 was submitted 6 times
5 was submitted 6 times
[boris@ServerCentOS8 Djobs]$ vi control.txt
[boris@ServerCentOS8 Djobs]$ cat control.txt|grep "6"|wc -l
6
[boris@ServerCentOS8 Djobs]$ cat control.txt|grep "5"|wc -l
6
[boris@ServerCentOS8 Djobs]$ cat control.txt|grep "7"|wc -l
6
No comments:
Post a Comment