artemgf

Квадратная страна

Nov 10th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <math.h>
  4. #include <string>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <sstream>
  8.  
  9. using namespace std;
  10.  
  11. string prom(string l)
  12. {
  13.     string h="";
  14.     int o = 4 - l.size();
  15.     for (int i = 0; i < o ; i++)
  16.         h += ' ';
  17.     return h;
  18. }
  19.  
  20. string convertInt(int number)
  21. {
  22.     stringstream ss;
  23.     ss << number;
  24.     return ss.str();
  25. }
  26.  
  27. void d(int n, int k, vector <string> russian)
  28. {
  29.     string h;
  30.     int j;
  31.     j = 0;
  32.     double q = k;
  33.     int f = ceil(n/q);
  34.     for (int i = 1; i <= f; i++)
  35.     {
  36.         h = "";
  37.         if (j != n-f*(k-1))
  38.         {
  39.             for (int p = 0; p < k; p++)
  40.             {
  41.                 h += prom(russian[p*f + i-1]);
  42.                 h += russian[p*f + i-1];
  43.             }
  44.             j++;
  45.         }
  46.         else
  47.         {
  48.             for (int p = 0; p < k - 1; p++)
  49.             {
  50.                 h += prom(russian[p*f + i - 1]);
  51.                 h += russian[p*f + i - 1];
  52.             }
  53.             h += "    ";
  54.         }
  55.         cout << h << endl;
  56.     }
  57. }
  58. int main()
  59. {
  60.     long long n, k, l;
  61.     vector <string> russian;
  62.     string prom;
  63.  
  64.     cin >> n >> k;
  65.  
  66.     for (int i = 1; i <= n; i++)
  67.     {
  68.         cin >> l;
  69.         prom = convertInt(l);
  70.         russian.push_back(prom);
  71.     }
  72.    
  73.     d(n, k, russian);
  74.    
  75.     _getch();
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment