9 degrees OJ--1164 (C ++), 9 degrees oj -- 1164

Source: Internet
Author: User

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;

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.