CCF认证真题-(201503-1)-图像旋转

 

思路1:

在输入时按照旋转后的矩阵将数字存入数组. 

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int arr[1005][1005];
 5 
 6 int main()
 7 {
 8     ios::sync_with_stdio(false);
 9     cin.tie(0);
10 
11     int n, m;
12     cin >> n >> m;
13     for (int i = 0; i < n; i++) {
14         int y = i;
15         for (int j = 0; j < m; j++) {
16             int item;
17             cin >> item;
18             int x = m - j - 1;
19             arr[x][y] = item;
20         }
21     }
22 
23     for (int i = 0; i < m; i++) {
24         for (int j = 0; j < n; j++) {
25             if (j == n - 1)
26                 cout << arr[i][j] << endl;
27             else
28                 cout << arr[i][j] << ' ';
29         }
30     }
31 
32     return 0;
33 }

 

 

思路1:

在输入时按照旋转前的矩阵将数字存入数组.

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 int arr[1005][1005];
 5 int main()
 6 {
 7     ios::sync_with_stdio(false);
 8     cin.tie(0);
 9     int n, m;
10     cin >> n >> m;
11     for (int i = 1; i <= n; i++)
12         for (int j = 1; j <= m; j++)
13             cin >> arr[i][j];
14     for (int i = m; i >= 1; i--) {
15         for (int j = 1; j <= n; j++) {
16             if (j == n)
17                 cout << arr[j][i];
18             else
19                 cout << arr[j][i] << ' ';
20         }
21         cout << endl;
22     }
23     return 0;
24 }
posted @ 2019-07-10 17:14  域Anton  阅读(195)  评论(0编辑  收藏  举报