Problem hidden
|This problem was hidden by Editorial Board member probably because it has incorrect language|version or invalid test data, or description of the problem is not clear.|

RGB7548 - Квадратын хүрээгээр

NxN хэмжээтэй квадрат массивыг жишээн дээрх загвараар дүүргэ.

Input

Квадрат массивын хэмжээ натурал тоо N өгөгдөнө. N<10.

Output

Квадрат массивын элементүүдийг мөр мөрөөр нь хэвлэнэ.

Гэхдээ элемент бүрийг 3 хоосон зайд хойш нь шахаж хэвлэнэ. Жишээг сайн ажиглана уу.

Жишээн дээрх 1-ийн тоо гэхэд урдаа, хойноо тус бүр 2 хоосон зайтай байна.

Мөн 16-ын тоо урдаа, хойноо тус бүр 1 хоосон зайтай байна.

Example

Input:
5

Output:
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9

Нэмсэн:Bataa
Огноо:2013-02-07
Хугацааны хязгаарлалт:1s
Эх кодын хэмжээний хязгаарлалт:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Програмчлалын хэлүүд:ADA95 ASM32 BASH BF C NCSHARP CSHARP C++ 4.3.2 CPP C99 CLPS LISP sbcl LISP clisp D ERL FORTRAN HASK ICON ICK JAVA JS-RHINO JULIA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON PYPY3 PYTHON3 RUBY SCALA SCM guile ST TCL WHITESPACE

hide comments
2023-11-22 02:11:05
shaahgun bno
2023-03-07 07:29:48
sug

Last edit: 2023-03-07 07:34:22
2022-12-30 12:23:24
Scanner scan=new Scanner(System.in);
int nu1=scan.nextInt();
int mas[][]=new int [10000][10000];
for(int i=1;i<=nu1;i++) {
for(int a=1;a<=nu1;a++) {
mas[i][a]=-1;
}
}
int a=1,b=0,c=1,d=1;
while(a<=nu1*nu1) {

if(b==0) {
if(mas[c][d]==-1) {
mas[c][d]=a;
a++;
d++;
}else {
d--;
b=1;
c++;
}
}
if(b==1) {
if(mas[c][d]==-1) {
mas[c][d]=a;
a++;
c++;
}else {
c--;
b=2;
d--;
}
}
if(b==2) {
if(mas[c][d]==-1) {
mas[c][d]=a;
a++;
d--;
}else {
d++;
b=3;
c--;
}
}
if(b==3) {
if(mas[c][d]==-1) {
mas[c][d]=a;
a++;
c--;
}else {
c++;
b=0;
d++;
}

}
}
for(int i=1;i<=nu1;i++) {
for(int w=1;w<=nu1;w++) {
System.out.print(mas[i][w]+" ");
}
System.out.print("\n");
}
2022-12-15 07:30:32
if(j%5==0){
cout << "\n";
}

}
else{
if(1<=b[i][j]&&10>=b[i][j]){
cout <<b[i][j]<<" "<<" ";
}
else {
cout <<b[i][j]<< " ";
}
if(j%5==0){
cout << "\n";
}
}
2022-12-15 07:27:26
#include <bits/stdc++.h>
using namespace std;
int main()
{long long a[10][10],s,k,i,j,n,m;
cin >>n;
s=1;
while(s<=n*n){
k=1;
i=k;
m=n;
for(j=k;j<=n;j++){
a[i][j]=s;
s++;
}
for(i=k; i<=n; i++){
a[i][j]=s;
s++;
}
i=m;
for(j=m-1; j>=k; j--){
a[i][j]=s;
s++;
}
for(i=m-1; j>=k+1; j++){
a[i][j]=s;
s++;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout <<a[i][j];

}
}
}
}
2022-12-15 06:59:54
s=1
while<s<=n*n>
k=1;
i=k;
m=n;
for(j=k;j<=n;j++){
a[i][j]=s;
s++;
}
for(i=k; i<=n; i++){
a[i][j]=s;
s++;
}
i=m;
for(j=m-1; j>=k; j--){
a[i][j]=s;
s++;
}
for(i=m-1; j>=k+1; j++){
a[i][j]=s;
s++;
}
2022-10-18 17:37:17
int nu1;
Scanner scan = new Scanner (System.in);
nu1=scan.nextInt();
int row=0,col=0;
int a=nu1-1;
int b=nu1-1;
int flag =1;
char move='r';
int mas[][]=new int[nu1][nu1];
for(int i=1;i<nu1*nu1+1;i++)
{
mas[row][col]=i;
switch(move)
{
case 'r':
col+=1;
break;
case 'd':
row+=1;
break;
case 'l':
col-=1;
break;
case 'u':
row-=1;
break;
}
if(i==a)
{
a+=b;
if(flag!=2)
{

flag=2;
}
else
{
b=b-1;

flag=1;
}

switch(move) {
case 'r':
move='d';
break;
case 'd':
move='l';
break;
case 'l':
move='u';
break;
case 'u':
move='r';
break;
}
}
}
for(int e=0;e<nu1;e++)
{
for(int q=0;q<nu1;q++)
{
System.out.print(mas[e][q]+" ");
}
System.out.print("\n");
}
2019-12-27 13:05:06
|Notes:|
1. Don't post any source code here.|
2. Please be careful, leave short comments only. Don't spam here.|
3. For more discussion (hints, ideas, solutions) please visit our forum.|
4. Authors are allowed to delete the post and use html code here (e.g. to provide some useful links).|
2019-11-20 11:31:06
#include <cstdio>

int main(){
int n;
scanf("%d",&n);
int a[100][100];
int d=1;
int m=n; //
int l=1;
int i,j;

// j == bagana
// i == mur
while(d<=n*n){
i=l;
for(j=l;j<=m;j++){
a[i][j]=d;
d++;
}
j=m;
for(i=l+1;i<=m;i++){
a[i][j]=d;
d++;
}
i=m;
for(j=m-1;j>=l;j--){
a[i][j]=d;
d++;
}
j=l;
for(i=m-1;i>=l+1;i--){
a[i][j]=d;
d++;
}
l++;
m--;
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
printf("%3d ",a[i][j]);
}
printf("\n");
}
}
2019-11-09 06:29:33
comment subminted
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.