1 solutions
-
0
C++ :
#include<iostream> #include<iomanip> using namespace std; int a[21][21]; int main() { int n; cin>>n; int t=1,k=1,x=2,y=0; while (t<=n*(n+1)/2) { while (x-1>=1 && y+1<=n) { a[--x][++y]=k++; t++; } a[x][++y]=k++; t++; while (x+1<=n && y-1>=1) { a[++x][--y]=k++; t++; } a[++x][y]=k++; t++; } for (int i=1; i<=n; i++) { for (int j=1; j<=n-i+1; j++) cout<<setw(4)<<a[i][j]; cout<<endl; } return 0; }
- 1
Information
- ID
- 17353
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By