1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 while(cin >> n) { 9 vector<vector<int>> matrix(n, vector<int>(n)); 10 int count = 0; 11 for(int i = 0; i < n; ++i) { 12 for(int k = i, j = 0; j <= i; k--, j++) { 13 count++; 14 matrix[k][j] = count; 15 } 16 } 17 18 for(int i = 0; i < n; ++i) { 19 for(int j = 0; j < n; ++j) { 20 if(matrix[i][j]) cout << matrix[i][j] << " "; 21 else cout << " "; 22 } 23 cout << endl; 24 } 25 } 26 return 0; 27 }
原文地址:https://www.cnblogs.com/joker1937/p/10609827.html
时间: 2024-10-28 18:00:00