Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Represent big numbers with dots
04-03-2010, 03:45 AM
Post: #1
Represent big numbers with dots
We all know that representing numbers bigger than a million is a problem.
For example if you have :
Code:
12429184782374982174
it is much easier to see it separated with spaces or dots in this case :
Code:
12.429.184.782.374.982.174
Now you can count triples and know how big is that number.
So i decided to post this simple problem.
Basically you need to count string from the end and on every third position from end to post a dot. If string is smaller or equal to 3 than you just write it.
Here is the code in Pascal :
Code:
program nums_with_dots;
uses wincrt;
var
s:string;
i,br:integer;
begin
readln(s);
if length(s)<4 then
  writeln(s)
else
  begin
  br:=0;
  for i:=length(s) downto 1 do
   begin
    br:=br+1;
    if br mod 3 = 0 then
      s:=copy(s,1,i-1)+'.'+copy(s,i,length(s));
   end;
   writeln(s);
  end;
end.
The biggest problem here is to understand copy() function.
About copy() function you have here :
http://www.pro9ramming.com/learnpascal/strings.html

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: