Welcome

>>>Welcome to my "CODE BAZAR"
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others

Update ✔✔✔ Upcoming programming book (.pdf) "Programming Contest (data structures and algorithms) by Md. Mahbub Hasan & "Graph Algorithms" by Safayat Asraf "****** Date: 20 March, 2019****Hazrat Ali****

Monday 31 October 2016


W. Simple Array

Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/W


Score: 1

CPU: 1s
Memory: 512MB

You will be given a grid of size n*n. Then you will be given n*n numbers of the grid. Now you have to print the number of grid from last column to first column of row n, then the numbers from last column to first column to row n-1 and in such way till row 1 . 

Suppose you have a grid of size 3 * 3 and the given numbers are 1 2 3 4 5 6 7 8 9. Then the number will be in the grid like below.
1 2 3
4 5 6
7 8 9 
Now your result will be 9 8 7 6 5 4 3 2 1 

Input
First you will be given a positive integer T (1< T <= 40), the number of test case. For each test case you will be given N( 0 < N < 50 ). Then in next lines there will be n*n positive integers separated by single space. No numbers will be greater than 1000.

Output
For each test case you have to print n*n numbers in reverse order separated by a single space.

Sample

InputOutput
2 3 1 2 3 4 5 6 7 8 9 5 5 4 1 2 6 9 8 7 4 5 5 6 4 7 8 1 2 3 6 5 4 5 6 9 79 8 7 6 5 4 3 2 1 7 9 6 5 4 5 6 3 2 1 8 7 4 6 5 5 4 7 8 9 6 2 1 4 5



Solution

#include<stdio.h>
int main()
{
    int i,j,k,t,n,ara[51][51];
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        scanf("%d",&n);
        for(j=0;j<n;j++){
            for(k=0;k<n;k++)
                scanf("%d",&ara[j][k]);
        }
        for(j=n-1;j>=n-1;j--)
            for(k=n-1;k>=n-1;k--)
            printf("%d",ara[j][k]);
        for(j=n-1;j>=n-1;j--)
            for(k=n-2;k>=0;k--)
                printf(" %d",ara[j][k]);
        for(j=n-2;j>=0;j--){
            for(k=n-1;k>=0;k--)
                printf(" %d",ara[j][k]);
            }
        printf("\n");
    }
        return 0;
}

No comments:

Post a Comment