Advertisement
Koral293

2.2

Apr 7th, 2020
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. main()
  6. {
  7. //2.2
  8.     int k;
  9.     cin >> k;
  10.     int n;
  11.     cin >> n;
  12.     //ma_foykarznrtitu_ima_
  13.     string S;
  14.     cin >> S;
  15.  
  16.     int kolumny = n/k;
  17.     char T[k][kolumny];
  18.    
  19.     int licz = 0;
  20.         for(int i = 0; i < k; i++)
  21.             {
  22.                 for(int j = 0; j < kolumny; j++)
  23.                 {
  24.                     T[i][j] = S[licz++];
  25.                 //  cout << T[i][j];
  26.                 }
  27.             }
  28.    
  29.     bool wDol = true;
  30.     int i = 0;
  31.     int j = 0;
  32.     licz = 0;
  33.    
  34.     while(licz!=n)
  35.     {  
  36.         if(wDol)
  37.         {
  38.             S[licz++] = T[i][j];
  39.             i++;
  40.         }
  41.         else
  42.         {
  43.             S[licz++] = T[i][j];
  44.             i--;
  45.         }
  46.        
  47.         if(i==k-1)
  48.         {
  49.             S[licz++] = T[i][j];
  50.             j++;
  51.             wDol = false;
  52.         }
  53.        
  54.         if(i==0)
  55.         {
  56.             S[licz++] = T[i][j];
  57.             j++;
  58.             wDol = true;
  59.         }  
  60.     };
  61.    
  62.     cout << S;
  63.            
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement