vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
This sounds like a trick question to me because if n was 50 or something and I gave the input 20, 30, 21, 49, 1, 35, ... 0 how would you be able to sort that without having a variable for each input.
To "sort" a bunch of input in ascending order with n numbers and no duplicates can be done by using a for() loop
for( int i = 0; i < n; i++ )
cout << i << endl;
sfuo
Practically a Master Poster
656 posts since Jul 2009
Reputation Points: 164
Solved Threads: 99
Output the numbers to the printer
Cut the numbers from the paper
Sort them on the table
Tape them together when sorted.
:icon_twisted:
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
The only thing I can think of is that maybe you are to use a stream iterator and loop through it outputting what you need each iteration. This seams like a very nonsense question.
NathanOliver
Veteran Poster
1,084 posts since Apr 2009
Reputation Points: 215
Solved Threads: 189
Yeah but if you think about it a file is pretty much a big array of characters so if he would let you do that then thats a joke.
sfuo
Practically a Master Poster
656 posts since Jul 2009
Reputation Points: 164
Solved Threads: 99
Since it says there are no duplicate inputs I'm guessing (and there is no way to check) there will be no need for checking if a duplicate number was entered. You can throw on a check to restrain input from [0,n).
This is what I came up with "1 day ago" according to this thread.
#include <iostream>
using namespace std;
int main()
{
int n = 10, inpt;
for( int i = 0; i < n; i++ )
cin >> inpt;
for( int i = 0; i < n; i++ )
cout << i << endl;
return 0;
}
sfuo
Practically a Master Poster
656 posts since Jul 2009
Reputation Points: 164
Solved Threads: 99