标签:
#include "iostream" using namespace std; int a[500][500]; bool rightOrDown = false; // initial go right bool dlOrUr = false; // down left or up right, initial go down left bool parallelOrDiagonal = false; // initial parallel; int diagonalStep = 1; int x = 0, y = 0; void moveParallel() { if(rightOrDown) x += 1; else y += 1; cout << a[x][y] << ‘ ‘; } void moveDiagonal() { for(int s=0; s<diagonalStep; s++) { if(dlOrUr) x -= 1, y += 1; else x += 1, y -= 1; cout << a[x][y] << ‘ ‘; } } int main() { int n; cin >> n; for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin >> a[i][j]; cout << a[x][y] << ‘ ‘; for(int i=0; i<2*n-2; i++) { moveParallel(); rightOrDown = !rightOrDown; moveDiagonal(); dlOrUr = !dlOrUr; if(i<=n-2) diagonalStep++; else diagonalStep--; if(i==n-2) diagonalStep -= 2, rightOrDown = !rightOrDown; } }
标签:
原文地址:http://www.cnblogs.com/meelo/p/5840288.html