View Single Post
Old 04-03-2005, 09:39 PM   #18
NrmMyth
Hero Gamer

 
Join Date: Jan 2005
Location: ,
Posts: 454
Thumbs up

Ok! here it is, the fast solution to "Number".
Bunch of if-s and all works...

long solution(long n)
{ long digits;

if(n<10)
digits=n;
else if(n<100)
digits=(n-9)<<1+9;
else if(n<1000)
digits=(n-99)*3+189;
else if(n<10000)
digits=(n-999)<<2+2889;
else if(n<100000)
digits=(n-9999)*5+38889;
else if(n<1000000)
digits=(n-99999)*6+488889;
else if(n<10000000)
digits=(n-999999)*7+5888889;
else if(n<100000000)
digits=(n-9999999)<<3+68888889;
else digits=788888889;

return digits;
}

It is'n very prety solution but on the other hand it is fast as lighting (:whistle: kung fu fighting).
And why can't I use tabulators! :ranting:
Any questions?
__________________
Never mess with me when I have a cougar, Never!
NrmMyth is offline                         Send a private message to NrmMyth
Reply With Quote