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

CCC '24 J5 - Harvest Waterloo

#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c, sr, sc; cin >> r; cin >> c; int p[r][c]; bool v

CCC '24 J4 - Troublesome Keys

#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main() { string ps; string ds; cin >> ps; cin >> ds;

CCC '22 J5 - Square Pool

#include<iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; bool rowcom(pair<int, int> a, pair<int, int> b){ return a.first < b.first; } bool colcom(pair<int,

Comentários


bottom of page