top of page

2018 CCC J3 c++ vector solution

# include <iostream>
# include <vector>
using namespace std;

void rotateAclockwise90Vector(vector < vector < int >> & A, int N)
{
  if (N < 2)
  {
    return;
  }
  bool flag = true;
  while (flag)
  {
     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--;
   }
  }
 }

int main()
{
    int N;
    vector < vector < int >> B;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
       vector < int > cur;
       for (int j = 0; j < N; j++){
          int c = 0;
          cin >> c;
          cur.push_back(c);
       }
       B.push_back(cur);
    }
    rotateAclockwise90Vector(B, N);
    for (int i = 0; i < N; i++)
    {
       for (int j = 0; j < N; j++){
         cout << B[i][j] << " ";
       }
       cout << endl;
    }
}

Recent Posts

See All

Comments


bottom of page