Jump to content

Input From File

- - - - -

  • Please log in to reply
4 replies to this topic

#1
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
I have a file that contains numbers in ascending form(max 2 digit) in a line in sorted form with no separation.

123111517224547

Now what i want to do is to read the number and display it on the console.
for this example the output will be
1 2 3 11 15 17 22 45 47

Now how can i do that since i have no delimiter ?

#2
rocketboy9000

rocketboy9000

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
Keep track of the size of the numbers, and the previous number's first digit. This will not always work though. Consider the two sets:
1 2 3
1 23
There is no way to distinguish other than by heuristics.

#3
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
yea the main problem with this is to find the point where the two digit number starts , I have made a logic and coded it that the program checks
if the 1st digit is 1 then save it , when the next 1 comes then naturally two digit number will start .

But the problem with this is that if there is no 1digit number then how will the program cater this problem.

#4
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
What if the numbers were
1234567890

1 < 2 < 3 < 4 < .. < 9
12 < 34 < 56 < 78 < 90
1 < 2 < 34 < 56 < 78 < 90
1 < 2 < 3 < 4 < 56 < 78 < 90
etc.

This leaves many possibly solutions.

#5
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
I have solved the problem . The numbers = always 20 so it was easy to check , that if there is no 1 digit number the length of string will be 40 , and so on .
Thanks for the replies :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users