Advertisement
Robert_JR

1319. Hotel

Oct 26th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. /*
  2.  * Rijoanul Hasan
  3.  * Timus 1319. Hotel
  4.  * C++
  5. */
  6.  
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <string>
  10. #include <iostream>
  11. #include <cstdlib>
  12. #include <vector>
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17.     int n;
  18.     while(cin >> n)
  19.     {
  20.         int array[n][n];
  21.         int i, j, k, value = 0;
  22.         for(i = n-1; i >= 0; i--)
  23.         {
  24.             k = 0;
  25.             for(j = i; j < n; j++)
  26.             {
  27.                 array[k++][j] = ++value;
  28.                 //cout << k-1 << j << ' ' << value << endl;
  29.             }
  30.         }
  31.         for(i = n-1; i >= 0; i--)
  32.         {
  33.             k = n-i;
  34.             for(j = 0; j < i; j++)
  35.             {
  36.                 array[k++][j] = ++value;
  37.                 //cout << k-1 << j << ' ' << value << endl;
  38.             }
  39.         }
  40.         for(i = 0; i < n; i++)
  41.         {
  42.             for(j = 0; j < n; j++)
  43.             {
  44.                 cout << array[i][j];
  45.                 if(j != n) cout << ' ';
  46.             }
  47.             cout << endl;
  48.         }
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement