为什么不对!!!

program ex6;
var n:longint;
x,i,j:integer;
s1:string;
sum:longint;
ch:char;
begin
readln(n,x);
ch:=chr(ord('0')+x);
sum:=0;
for i:=1 to n do
begin
str(i,s1);
for j:=1 to length(s1) do
if ch=s1[j] then sum:=sum+1;
end;
writeln(sum);
end.

1 条评论

  • @ 2017-02-07 13:42:40

    i 要循环到 n 呀
    代码:
    program ex6;
    var
    n,i:longint;
    x,j:integer;
    s1:string;
    sum:longint;
    ch:char;
    begin
    readln(n,x);
    ch:=chr(ord('0')+x);
    sum:=0;
    for i:=1 to n do
    begin
    str(i,s1);
    for j:=1 to length(s1) do
    if ch=s1[j] then sum:=sum+1;
    end;
    writeln(sum);
    end.

  • 1

信息

ID
1848
难度
5
分类
(无)
标签
递交数
16586
已通过
5810
通过率
35%
被复制
36
上传者