Advertisement
Spocoman

04. Snake Moves

Jan 27th, 2024 (edited)
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int row, col;
  9.     cin >> row >> col;
  10.     cin.ignore();
  11.  
  12.     string line;
  13.     getline(cin, line);
  14.  
  15.     vector<vector<char>> matrix;
  16.  
  17.     int index = 0;
  18.  
  19.     for (int i = 0; i < row; i++) {
  20.         vector<char> currentRow;
  21.         for (int j = 0; j < col; j++) {
  22.             if (i % 2 == 0) {
  23.                 currentRow.push_back(line[index++ % line.length()]);
  24.             }
  25.             else {
  26.                 currentRow.insert(currentRow.begin(), line[index++ % line.length()]);
  27.             }
  28.         }
  29.         matrix.push_back(currentRow);
  30.     }
  31.  
  32.     for (int i = 0; i < row; i++) {
  33.         for (int j = 0; j < col; j++) {
  34.             cout << matrix[i][j];
  35.         }
  36.         cout << endl;
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement