top of page

CCC 2018 J4/S2: Sunflowers

Updated: Oct 30, 2021

Matrix rotated anti clockwise 90 degree, next 90 degree (180 degree), next 90 degress(270 degree), next 90 degree(360 degree).


Look the example:

Assume one matrix is:

1 2 3

4 5 6

7 8 9

This is anti clockwise 90 degree

3 6 9

2 5 8

1 4 7

This is anti clockwise 90 degree

9 8 7

6 5 4

3 2 1

This is anti clockwise 90 degree

7 4 1

8 5 2

9 6 3

this is anti clockwise 90 degree

1 2 3

4 5 6

7 8 9



#include <iostream>

using namespace std;


int main() {

int N;

cin >> N;

int A[N][N];

for(int i = 0; i < N; i++){

for(int j = 0; j < N; j++){

cin >> A[i][j];

}

}

if(N >= 2){

while(true){

if (A[0][0] < A[0][N-1] &&

A[0][0] < A[N-1][0] &&

A[N-1][0] < A[N-1][N-1] &&

A[0][N-1] < A[N-1][N - 1]){

break;

}

for(int i = 0; i < N; i++){

for(int j = i; j < N; j++){

int t = A[i][j];

A[i][j] = A[j][i];

A[j][i] = t;

}

}

int i = 0;

int j = N-1;

while(i < j){

for(int k = 0; k < N; k++){

int t = A[i][k];

A[i][k] = A[j][k];

A[j][k] = t;

}

i++;

j--;

}




}


}

for(int i = 0; i < N; i++){

for(int j = 0; j < N; j++){

cout<<A[i][j]<<" ";

}

cout<<endl;

}


}



N = int(input())

clist = []

for i in range(N):
    cur = []
    s = input().split()
    for j in range(N):
        cur.append(int(s[j]))
    clist.append(cur)


def rotateAclockwise90():
    if N < 2:
        return
    for i in range(N):
        for j in range(i, N):
            t = clist[i][j]
            clist[i][j] = clist[j][i]
            clist[j][i] = t
    i = 0
    j = N -1
    while i < j:
        for k in range(N):
            t = clist[i][k]
            clist[i][k] = clist[j][k]
            clist[j][k] = t
        i += 1
        j -= 1


for i in range(4):
    if clist[0][0] < clist[0][N-1] and \
       clist[0][0] < clist[N-1][0] and \
       clist[N-1][0] < clist[N-1][N-1] and \
       clist[0][N-1] < clist[N-1][N - 1]:
        break
    rotateAclockwise90()

for x in clist:
    print(*x, sep=' ')

Recent Posts

See All

CCC '24 J5 - Harvest Waterloo

#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c,...

CCC '24 J4 - Troublesome Keys

s1 = input() s2 = input() silly = '' silly_o = '' quiete = '-' i = 0 j = 0 while i < len(s1) and j < len(s2): if s1[i] != s2[j]: if...

CCC '22 J5 - Square Pool

#include<iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; bool rowcom(pair<int, int> a, pair<int,...

Comments


One-time Donations
I hope I can solve all CCC problems!,
Please e-transfer cccottawa862008@gmail.com

Subscribe to AIOICode newsletter

I'm a title. ​Click here to edit me.

Thanks for submitting!

  • Twitter
  • Facebook
  • Linkedin

© 2023 by AIOICode.

bottom of page