level 6
ijpoj
楼主
第一题:计数问题.
program count;
var
n,i,m,t:longint;
begin
assign(input,'count.in');
reset(input);
assign(output,'count.out');
rewrite(output);
readln(n,m);
t:=0;
for i:=1 to n do begin
if (i>=0)and(i<=9) then begin
if i=m then inc(t);
end;
if (i>=10)and(i<=99) then begin
if i div 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=100)and(i<=999) then begin
if i div 100 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=1000)and(i<=9999) then begin
if i div 1000 = m then inc(t);
if i div 100 mod 10 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=10000)and(i<=99999) then begin
if i div 10000 = m then inc(t);
if i div 1000 mod 10 = m then inc(t);
if i div 100 mod 10 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=100000)and(i<=999999) then begin
if i div 100000 = m then inc(t);
if i div 10000 mod 10 = m then inc(t);
if i div 1000 mod 10 = m then inc(t);
if i div 100 mod 10 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=1000000)and(i<=9999999) then begin
if i div 1000000 = m then inc(t);
if i div 100000 mod 10 = m then inc(t);
if i div 10000 mod 10 = m then inc(t);
if i div 1000 mod 10 = m then inc(t);
if i div 100 mod 10 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
end;
writeln(t);
close(input);
close(output);
end.
2013年11月19日 05点11分
1
program count;
var
n,i,m,t:longint;
begin
assign(input,'count.in');
reset(input);
assign(output,'count.out');
rewrite(output);
readln(n,m);
t:=0;
for i:=1 to n do begin
if (i>=0)and(i<=9) then begin
if i=m then inc(t);
end;
if (i>=10)and(i<=99) then begin
if i div 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=100)and(i<=999) then begin
if i div 100 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=1000)and(i<=9999) then begin
if i div 1000 = m then inc(t);
if i div 100 mod 10 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=10000)and(i<=99999) then begin
if i div 10000 = m then inc(t);
if i div 1000 mod 10 = m then inc(t);
if i div 100 mod 10 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=100000)and(i<=999999) then begin
if i div 100000 = m then inc(t);
if i div 10000 mod 10 = m then inc(t);
if i div 1000 mod 10 = m then inc(t);
if i div 100 mod 10 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
if (i>=1000000)and(i<=9999999) then begin
if i div 1000000 = m then inc(t);
if i div 100000 mod 10 = m then inc(t);
if i div 10000 mod 10 = m then inc(t);
if i div 1000 mod 10 = m then inc(t);
if i div 100 mod 10 = m then inc(t);
if i div 10 mod 10 = m then inc(t);
if i mod 10 = m then inc(t);
end;
end;
writeln(t);
close(input);
close(output);
end.