Submit | All submissions | Best solutions | Back to list |
PFORLOOP - For Loops Challenge |
Bjarne is learning about programming. Yesterday’s lesson was about for loops. To put his skills into practice, he had to write a number of for loops that printed consecutive positive integers. He was so proud of his creation that he stored the output of his program into a file. For example, the contents of the file could have looked like this:
5 6 7 8 9 10 11 12 13 14 56 57 58 59 60 61 62 63 64 65 100 101 102 103 104 105 106
Today, he opened his file and realized it is now inconsistent: the numbers weren’t sorted in ascending order anymore! His wife told him she was bored so she swapped some numbers around. He’s so frustrated he can’t rewrite the program.
Your task is to help him out. Read out the numbers and print all the C++ for loops that recreate the original file.
Input
There are many lines in the input. The i-th line contains a sequence of space-separated positive integers, where each integer is between 0 and 1000000000. It is guaranteed there are no repeated integers and that there will be at minimum one line with one integer, no line will have more than 1000 integers.
Output
Output all the for loops that generate Bjarne’s original file, one per line. Print the for loops in order. That is, if the numbers of the i-th loop are less than the numbers of the j-th loop, the i-th for loop must be printed first.
Notes
- Name ‘i’ the variable of each for loop.
- Don’t use brackets.
- The for loop condition must be inclusive, that is, use ‘<=’.
- The increment section of the for loop must be "i++".
- The C++ code you print need not include a line ending command.
- Beware of spaces. All your for loops must contain the same number of spaces as this sample:
for (int i = a; i <= b; i++) cout << i << " ";
Example
Input 9 6 100 1 3 105 2 4 101 102 103 104 5 7 8 Output for (int i = 1; i <= 9; i++) cout << i << " "; for (int i = 100; i <= 105; i++) cout << i << " ";
Added by: | kojak_ |
Date: | 2012-12-15 |
Time limit: | 2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | OPPAI Practice Problems |
hide comments
|
|||||
2014-02-12 15:11:16 Bhavik
nice one.. |
|||||
2013-12-15 01:38:28 Apoorv Jindal
Is the output format specified in the question correct? |
|||||
2013-12-12 06:20:08 RIVU DAS
help me....getting WA!! |
|||||
2013-08-17 19:17:55 Hitman
AC at one go !!! |
|||||
2013-08-16 12:23:52 Amit RC
Unfortunately it seems you can't trust even the given output for exact output format...Copy pasting the given output wont work!! |
|||||
2013-08-04 04:52:11 aqfaridi
@realsteel(BJ) for (int i = 1; i <= 9; i++) cout << i << " "; |
|||||
2013-07-27 23:04:11 Bharat Jain
what is the o/p of 4 5 6 7 9 8 2 1 3 Last edit: 2013-07-27 23:12:48 |
|||||
2013-07-26 14:33:49 stranger
could you answer one question? suppose that we have the next input 4 5 6 2 3 1 101 102 103 104 105 106 the output could be both 1 2 3 4 5 6 101 102 103 104 105 106 and 1 2 3 4 5 6 101 102 103 104 105 105 which one is correct? maybe i missed something in description |
|||||
2013-07-25 09:00:23 aqfaridi
for kids .. |