fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n, a[22][22];
  5.  
  6. int main() {
  7. cin>>n;
  8. for(int i=0;i<n;i++) {
  9. for(int j=0;j<n;j++) {
  10. cin>>a[i][j];
  11. }
  12. }
  13.  
  14. for(int i=0;i<n;i++) {
  15. for(int j=n-1;j>=n-1-i;j--) {
  16. cout<<a[i][j]<<endl;
  17. }
  18.  
  19. for(int j=i-1;j>=0;j--) {
  20. cout<<a[j][n-1-i]<<endl;
  21. }
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 4288KB
stdin
3
1 2 3
4 5 6
7 8 9
stdout
3
6
5
2
9
8
7
4
1