Algorithm


Problem Name: beecrowd | 1177

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

Array Fill II

 

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Write a program that reads a number T and fill a vector N[1000] with the numbers from 0 to T-1 repeated times, like as the example below.

 

Input

 

The input contains an integer number T (2 ≤ T ≤ 50).

 

Output

 

For each position of the array N, print "N[i] = x", where i is the array position and x is the number stored in that position.

 

 

 

Input Sample Output Sample

3

N[0] = 0
N[1] = 1
N[2] = 2
N[3] = 0
N[4] = 1
N[5] = 2
N[6] = 0
N[7] = 1
N[8] = 2
...

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    int T;
    cin >> T;
    int k = 0;
    while(true){
        for(int x = 0; x  <  T; x++){
            cout << "N[" << k << "] = " << x << "\n";
            k += 1;
            if(k == 1000){
                break;
            }
        }
        if(k == 1000){
            break;
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3

Output

x
+
cmd
N[0] = 0 N[1] = 1 N[2] = 2 N[3] = 0 N[4] = 1 N[5] = 2 N[6] = 0 N[7] = 1 N[8] = 2 ...

#2 Code Example with Javascript Programming

Code - Javascript Programming


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

let T = parseInt(lines.shift());
let k = 0;
while(true){
    for(var x = 0; x  <  T; x++){
        console.log(`N[${k}] = ${x}`);
        k += 1;
        if(k === 1000){
            break;
        }
    }
    if(k === 1000){
        break;
    } 
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3

Output

x
+
cmd
N[0] = 0 N[1] = 1 N[2] = 2 N[3] = 0 N[4] = 1 N[5] = 2 N[6] = 0 N[7] = 1 N[8] = 2 ...

#3 Code Example with Python Programming

Code - Python Programming


T = int(input())
k = 0
while True:
    for x in range(0, T):
        print(f'N[{k}] = {x}')
        k += 1
        if k == 1000:
            break
    if k == 1000:
        break
Copy The Code & Try With Live Editor

Input

x
+
cmd
3

Output

x
+
cmd
N[0] = 0 N[1] = 1 N[2] = 2 N[3] = 0 N[4] = 1 N[5] = 2 N[6] = 0 N[7] = 1 N[8] = 2 ...
Advertisements

Demonstration


Previous
#1176 Beecrowd Online Judge Solution 1176 Fibonacci Array Solution in C++, Java, Js and Python
Next
#1178 Beecrowd Online Judge Solution 1178 Array Fill III Solution in C++, Java, Js and Python