ZeroJudge K632: Generating Random Number

In many cases, we do need to use a program to randomly generate a sequence composed of numbers from 1 to N.

For example: randomly sorting students numbered from 1 to N, randomly sorting balloons numbered from 1 to N for testing, and so on.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
Input a positive integer N (N < 2147483647).Output a random sequence of numbers from 1 to N, separated by spaces.
32 1 3
55 3 2 1 4

Thought Process

Since outputting from 1 to N is also a possible random ordering, you can simply use a for loop to output from 1 to N.

Sample Code-ZeroJudge K632: Generating Random Number

#include <iostream>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    for (int i = 0; i<N; i++)
    {
        cout << i+1 << " ";
    }
    cout << "\n";
}

//Z.O.J. K632
//Dr. SeanXD

Comments