View Single Post
Old 02-03-2005, 08:00 PM   #15
Unknown Hero
Home Sweet Abandonia

 
Join Date: Aug 2004
Location: Split, Croatia
Posts: 1,028
Default

Here's my solution for Number:

program broj;
var n,x,i:longint;
begin
x:=0;
readln(n);
for i:= 1 to n do
begin
if (i<10) then
x:=x+1
else if (i<100) then
x:=x+2
else if (i<1000) then
x:=x+3
else if (i<10000) then
x:=x+4
else if (i<100000) then
x:=x+5
else if (i<1000000) then
x:=x+6
else if (i<10000000) then
x:=x+7
else if (i<100000000) then
x:=x+8;
end;
writeln(x);
end.



Here's optimal solution for the Number:

program broj;
var n, rj, i : longint;
begin
readln(n);
rj := n;
i := 9;
while n>i do
begin
n := n-i;
rj := rj + n;
i := i*10;
end;
writeln(rj);
end.
Unknown Hero is offline                         Send a private message to Unknown Hero
Reply With Quote