Algorithm


Problem Name: beecrowd | 1534

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

Array 123

 

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Read an integer N that is the size of a bidimentional array that must be printed like the given example.

 

Input

 

The input contains many test cases and ends with EOF. Each test case consist in a integer number N (3 ≤ N < 70), that indicates the size (lines and columns) of a bidimentional array that must be printed.

 

Output

 

For each N read, print the output according to the given example.

 

 

 

Sample Input Sample Output

4

7

1332

3123

3213

2331

1333332

3133323

3313233

3332333

3323133

3233313

2333331

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include<stdio.h>
int main()
{
    int i,j,k,n,ar[72][72];;
    while(scanf("%d",&n)!=EOF)
    {
        k=n-1;
        for(i = 0; i  <  n; i++)
        {
            for(j = 0; j  <  n; j++)
            {
                if(i==j)
                {
                    ar[i][j]=1;
                }
                else
                    ar[i][j]=3;
                if(j==k)ar[i][j]=2;
            }
            k--;
        }
        for(i = 0; i < n; i++)
        {
            for(j = 0; j  <  n; j++)
            {
                printf("%d",ar[i][j]);
            }
            printf("\n">;
        }

    }


    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 7

Output

x
+
cmd
1332 3123 3213 2331 1333332 3133323 3313233 3332333 3323133 3233313 2333331

#2 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var prompt = function(texto) { return lines.shift();};

var size = parseInt(prompt());

while (size > 0) {
  var M = [];

  for (let i = 0; i  <  size; i++) {
    let line = [];

    for (let n = 0; n  <  size; n++) {
      let aux = 0;
      if (i == n) {
        aux = 2;
      }
      if (i + n + 1 == size) {
        aux = 1;
      }

      line.push(3 - aux);
    }
    console.log(line.join(""));
  }
  size = parseInt(prompt());
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 7

Output

x
+
cmd
1332 3123 3213 2331 1333332 3133323 3313233 3332333 3323133 3233313 2333331
Advertisements

Demonstration


Previous
#1533 Beecrowd Online Judge Solution 1533 Detective Watson Solution in C, C++, Java, Js and Python
Next
#1536 Beecrowd Online Judge Solution 1536 Libertadores Solution in C, C++, Java, Js and Python