Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <string>
- std::string repeatWord(std::string& word) {
- std::string repeated;
- for (int i = 0; i < 100; ++i) {
- repeated.append(word);
- }
- return repeated;
- }
- void makeSnake(std::list<std::list<char>>& snakeWords, std::string& word, int& rows, int& cols) {
- int wordIndex = 0;
- for (int i = 0; i < rows; ++i) {
- std::list<char> row;
- for (int j = 0; j < cols; ++j) {
- if (i % 2 == 0) {
- row.push_back(word[wordIndex]);
- }
- else {
- row.push_front(word[wordIndex]);
- }
- wordIndex++;
- }
- snakeWords.push_back(row);
- }
- }
- void printSnake(std::list<std::list<char>>& snakeWords) {
- for (auto& row : snakeWords) {
- for (auto& elem : row) {
- std::cout << elem;
- }
- std::cout << std::endl;
- }
- }
- int main() {
- int rows, cols;
- std::string word;
- std::cin >> rows >> cols >> word;
- std::list<std::list<char>> snakeWords;
- word = repeatWord(word);
- makeSnake(snakeWords, word, rows, cols);
- printSnake(snakeWords);
- }
Add Comment
Please, Sign In to add comment