ITGUY67 - Editorial

Problem: Contest Page | CodeChef

DIFFICULTY:

EASY.

PROBLEM:

The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.

Program:

#include<bits/stdc++.h>
using namespace std;
 
int main()
 {
	//code
	
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int x;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                x = min(min(i, j),min(n - i - 1, n - j - 1));
                if (i <= j)
                    cout<< (n - 2 * x) * (n - 2 * x) - (i - x) - (j - x)<<" ";
                else
                    cout<< (n - 2 * x - 2) * (n - 2 * x - 2) + (i - x) + (j - x)<<" ";
            }
            cout<<endl;
        }
	}
}