Algorithm


Problem Name: beecrowd | 1146

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1146

Growing Sequences

 

Adapted by Neilor Tonin, URI Brazil

Timelimit: 2

Your program must read an integer X indefinited times (the program must stop when X is equal to zero). For each X print the sequence from 1 to X, with one space between each one of these numbers.

PS: Be carefull. Don't leave any space after the last number of each line, otherwise you'll get Presentation Error.

 

Input

 

The input file contains many integer numbers. The last one is zero.

 

Output

 

For each number N of the input file, one output line must be printed, from 1 to N like the following example. Be careful with blank spaces after the last line number.

 

 

 

Input Sample Output Sample

5
10
3
0

1 2 3 4 5
1 2 3 4 5 6 7 8 9 10
1 2 3

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>

using namespace std;

int main(){
    while(1){
        int x;
        cin >> x;
        if (x == 0){
            break;
        }
        int i;
        for(i = 1; i  <  x; i++){
            cout << i << " ";
        }
        cout << i << endl;
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 1 2 3

Output

x
+
cmd
5 10 3 0

#2 Code Example with Java Programming

Code - Java Programming


import java.io.IOException;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) throws IOException{
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        while(x != 0){
            for(int i = 1; i  <  x; i++){
                System.out.printf("%d ", i);
            }
            System.out.println(x);
            x = input.nextInt();
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 1 2 3

Output

x
+
cmd
5 10 3 0

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

while(true){
    var x = parseInt(lines.shift());
    if (x === 0){
        break;
    }
    var i;
    for(i = 1; i  <  x; i++){
        process.stdout.write(i+ " ");
    }
    console.log(i);
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 1 2 3

Output

x
+
cmd
5 10 3 0

#4 Code Example with Python Programming

Code - Python Programming


while(True):
    x = int(input())
    if (x == 0):
        break
    else:
        for i in range(1, x):
            print(i, end=" ")
        print(x)
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 1 2 3

Output

x
+
cmd
5 10 3 0
Advertisements

Demonstration


Previous
#1145 Beecrowd Online Judge Solution 1145 Logical Sequence 2 Solution in C++, Java, Js and Python
Next
#1147 Beecrowd Online Judge Solution 1147 Knight Scape Solution in C, C++, Java, Js and Python