标签:pre using span names cin ios sync oid return
1 #include <iostream> 2 using namespace std; 3 int arr[505][505]; 4 bool flag; 5 int n; 6 void printComp(int x1, int y1, int x2, int y2) 7 { 8 int i = x1, j = y1; 9 if (x1 == n && x2 == n) { 10 cout << arr[n][n] << endl; 11 return; 12 } 13 if (!flag) { 14 // 斜向上 15 while (i >= 1 && j <= y2) { 16 cout << arr[i][j] << ‘ ‘; 17 i--; 18 j++; 19 } 20 } 21 else { 22 // 斜向下 23 while (i <= x2 && j >= 1) { 24 cout << arr[i][j] << ‘ ‘; 25 i++; 26 j--; 27 } 28 } 29 } 30 31 int main() 32 { 33 ios::sync_with_stdio(false); 34 cin.tie(0); 35 cin >> n; 36 for (int i = 1; i <= n; i++) 37 for (int j = 1; j <= n; j++) 38 cin >> arr[i][j]; 39 flag = false; 40 for (int i = 1; i <= n; i++) { 41 if (!flag) 42 printComp(i, 1, 1, i); 43 else 44 printComp(1, i, i, 1); 45 flag = !flag; 46 } 47 48 for (int i = 2; i <= n; i++) { 49 if (!flag) 50 printComp(n, i, i, n); 51 else 52 printComp(i, n, n, i); 53 flag = !flag; 54 } 55 return 0; 56 }
标签:pre using span names cin ios sync oid return
原文地址:https://www.cnblogs.com/AntonLiu/p/11164686.html