对了,把这个也发上来,昨天晚上写的……转换成string真的是一个不错的方法。
program two; var st:string; l,r,i,n,s:longint; begin s := 0; read (l,r); for n := l to r do begin str(n,st); for i := 1 to length(st) do if st[i]='2' then inc(s); end; writeln (s); end.
program two; var st:string; l,r,i,n,s:longint; begin s := 0; read (l,r); for n := l to r do begin str(n,st); for i := 1 to length(st) do if st[i]='2' then inc(s); end; writeln (s); end.