9 degrees OJ--1164 (C ++), 9 degrees oj -- 1164
# Include <iostream>
# Include <vector>
Using namespace std;
Int main (){
Int n; // n indicates the matrix order.
While (cin> n ){
Int x, y, I, j; // used for Loop Control
Vector <int> vec1 (n, vector <int> (n ));
Vector <int> vec2 (n, vector <int> (n ));
// Store data into a dynamic array
For (x = 0; x <n; x ++ ){
For (y = 0; y <n; y ++ ){
Int mid; // intermediate variable, used to store data into vec1
Cin> mid;
Vec1 [x] [y] = mid;
}
}
For (x = 0; x <n; x ++ ){
For (y = 0; y <n; y ++ ){
Int mid; // intermediate variable, used to store data into vec2
Cin> mid;
Vec2 [x] [y] = mid;
}
}
Int flag = 0; // used to determine whether all elements conform to the rotation angle; flag = 1; no flag = 0
Int angle =-1; // record the Rotation angle
// Determine whether the rotation angle is 0
For (I = 0; I <n; I ++ ){
For (j = 0; j <n; j ++ ){
If (vec1 [I] [j] = vec2 [I] [j]) {
Flag = 1;
Continue;
}
Else {
Flag = 0;
Break;
}
}
If (flag = 1 ){
Continue;
}
Else {
Break;
}
}
If (flag = 1 ){
Angle = 0;
Cout <angle <endl;
Continue;
}
Else {
Angle =-1;
}
// Determine if the rotation angle is 90
For (I = 0; I <n; I ++ ){
For (j = 0; j <n; j ++ ){
If (vec1 [I] [j] = vec2 [j] [n-1-i]) {
Flag = 1;
Continue;
}
Else {
Flag = 0;
Break;
}
}
If (flag = 1 ){
Continue;
}
Else {
Break;
}
}
If (flag = 1 ){
Angle = 90;
Cout <angle <endl;
Continue;
}
Else {
Angle =-1;
}
// Determine whether the rotation angle is 180
For (I = 0; I <n; I ++ ){
For (j = 0; j <n; j ++ ){
If (vec1 [I] [j] = vec2 [n-1-i] [n-1-j]) {
Flag = 1;
Continue;
}
Else {
Flag = 0;
Break;
}
}
If (flag = 1 ){
Continue;
}
Else {
Break;
}
}
If (flag = 1 ){
Angles = 180;
Cout <angle <endl;
Continue;
}
Else {
Angle =-1;
}
// Determine whether the rotation angle is 279
For (I = 0; I <n; I ++ ){
For (j = 0; j <n; j ++ ){
If (vec1 [I] [j] = vec2. [n-1-j] [I]) {
Flag = 1;
Continue;
}
Else {
Flag = 0;
Break;
}
}
If (flag = 1 ){
Continue;
}
Else {
Break;
}
}
If (flag = 1 ){
Angles = 270;
Cout <angle <endl;
Continue;
}
Else {
Angle =-1;
}
// If none of the above conditions are met
If (angle =-1 ){
Cout <angle <endl;
Continue;
}
}
Return 0;
}