8 solutions
-
0
#include<bits/stdc++.h> using namespace std; int g[21][21]; int main(){ int n; cin>>n; int cnt=1; for(int i=1;i<=n;i++){ if(i%2==0){ for(int x=1,y=i;x<=i;x++,y--){ g[x][y]=cnt++; } }else{ for(int x=i,y=1;y<=i;x--,y++){ g[x][y]=cnt++; } } } for(int i=1;i<=n;i++){ for(int j=1;j<=n-i+1;j++){ cout<<g[i][j]<<' '; } cout<<endl; } return 0; }
Information
- ID
- 82
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 4
- Tags
- (None)
- # Submissions
- 89
- Accepted
- 30
- Uploaded By