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 |
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
Output
#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
Output
#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
Output