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.|

RGB7545 - Утга олголт 5


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

Input

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

Output

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

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

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

Example

Input:
5

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

 


Нэмсэн: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
2024-09-02 03:43:10
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int too = in.nextInt();
int n = too*too;
for(int i=0; i<too; i++){
if(i%2==0){
for(int j=0; j<too; j++){
System.out.print(n);
n = n - 1;
if(n<10){
System.out.print(" ");
}
else System.out.print(" ");
}
System.out.println();
}
else {
n = n - too;
for(int j=0; j<too; j++){
n = n + 1;
System.out.print(n);
if(n<10){
System.out.print(" ");
}
else System.out.print(" ");
}
n=n-too;
System.out.println();
}
}
}
}


in java you can try this one if u'r an idiot :]. published by choko
2024-02-24 06:39:50
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, i, j;
cin>>n;
int a[n][n];
for(j = 1; j <= n; j++){
if(j % 2 == 0){
for(i = (n - j) * n + 1; i <= (n - j + 1) * n; i++){
if(i / 10 < 1) cout << " ";
cout << i << " ";
}
}
else
{
for(i = (n - j + 1) * n; i >= n * (n - j) + 1; i--){
if(i / 10 < 1) cout << " ";
cout << i << " ";
}
}
cout << endl;
}
return 0;
}

Last edit: 2024-02-24 06:40:46
2023-11-28 16:47:16
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,i,k,j,s;
cin>>n;
for(i=n;i>=1;i--){
if(i%2!=0){
for(j=i*n;j>=i*n-(n-1);j--){
if(j<10){
cout<<" "<<j;
}
else{
cout<<" "<<j;
}
}
cout<<endl;
}
else{
for(j=i*n-(n-1);j<=i*n;j++){
if(j<10){
cout<<" "<<j;
}
else{
cout<<" "<<j;
}
}
cout<<endl;
}
}
return 0;
}

Last edit: 2023-12-04 14:15:32
2023-11-22 01:55:42
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, i, j;
cin>>n;
int a[n][n];
for(j=1;j<=n;j++){
if(j%2==0){
for(i=(n-j)*n+1;i<=(n-j+1)*n;i++){
if(i/10<1) cout<<" ";
cout<<i<<" ";
}
}
else{
for(i=(n-j+1)*n;i>=n*(n-j)+1;i--){
if(i/10<1) cout<<" ";
cout<<i<<" ";
}
}
cout<<endl;
}
return 0;
}
2023-01-09 09:12:42
ika giin bodlogiig huularay #include<stdio.h>
#include<math.h>
main()
{
int i,n,j,t,a[100][100];
scanf("%d",&n); t=1;
for (i=n-1;i>=0;i--) {
for(j=n-1; j>=0 ;j--) {a[i][j]=t; t++;}
i--;
for(j=0; j<n ;j++) {a[i][j]=t; t++;}}

for (i=0;i<n;i++) {
for(j=0; j<n ;j++) printf("%3d",a[i][j]);
printf("\n");
}
}
2022-11-05 15:40:32
#include <iostream>

using namespace std;

int main()
{
int n, s ;
cin >> n ;
s=n*n;
int a[100][100] ;
for(int i=1; i<=n ; i++){
for (int j=1 ; j<=n; j++){
a[i][j]=s;
s--;
}
}
for(int i=1; i<=n ; i++){
for (int j=1 ; j<=n; j++){
if (i%2==0){

if (a[i][n-j+1]<10){
cout << " "<< a[i][n-j+1];
}
else {
cout << " "<< a[i][n-j+1];
}
}
else {
if (a[i][j]<10)
cout << " "<< a[i][j];
else
cout << " "<< a[i][j];
}
}
cout << endl;
}
return 0;
}


ku-giinhan huul moi
Fudu-gees

Last edit: 2022-11-05 15:43:12
2022-10-24 06:34:25
#include<cstdio>
int main(){
int a[100][100],s,i,j,n;
scanf("%d",&n);
s=n*n;
for(i=1;i<=n;i++){
if(i%2==1){
for(j=1;j<=n;j++) {
a[i][j]=s;
s=s-1;}}
if(i%2==0){
for(j=n;j>=1;j--) {
a[i][j]=s;
s=s-1;}}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
printf("%d ",a[i][j]); }
printf("\n");}
return 0;
}
2022-10-24 06:32:59
#include<cstdio>
int main(){
int a[100][100],s,i,j,n;
scanf("%d",&n);
s=n*n;
for(i=1;i<=n;i++){
if(i%2==1){
for(j=1;j<=n;j++) {
a[i][j]=s;
s=s-1;}}
if(i%2==0){
for(j=n;j>=1;j--) {
a[i][j]=s;
s=s-1;}}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
printf("%d ",a[i][j]); }
printf("\n");}
return 0;
}
2022-10-12 05:48:38
#include<stdio.h>
int main(){
int i,j,n,t=1;
scanf("%d",&n);
int a[n][n];
t=n*n;
for (i=0;i<n;i++){
if(i%2==0){
for(j=0;j<n;j++){
a[i][j]=t;
t--;
}
}
else{
for(j=n-1;j>=0;j--){
a[i][j]=t;
t--;
}

}
}for (i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%3d",a[i][j]);
}
printf("\n");
}
}
2020-01-08 04:09:05
#include<bits/stdc++.h>

using namespace std;

int main(){
long long a,b,p,n,k,s,i,j;

cin>>n;

s=n;
for(i=1; i<=n; i++){
if(i%2==0){
for(j=n*(s-1)+1; j<=s*n; j++){
if(j>9) cout<<" "<<j<<" ";
else cout<<" "<<j<<" ";
}
}else {
for(j=s*n; j>(s-1)*n; j--){
if(j>9) cout<<" "<<j<<" ";
else cout<<" "<<j<<" ";
}
}
s--;
cout<<endl;
}

return 0;
}
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.