Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main() {
- string line;
- getline(cin, line);
- int n = stoi(line.substr(0, line.find(',')));
- string method = line.substr(line.size() - 1);
- vector<vector<int>> matrix;
- for (size_t i = 0; i < n; i++) {
- matrix.push_back(vector<int>(n));
- }
- int counter = 1;
- for (int c = 0; c < n; c++) {
- if (c % 2 == 1 && method == "B") {
- for (int r = n - 1; r >= 0; r--) {
- matrix[r][c] = counter++;
- }
- }
- else {
- for (int r = 0; r < n; r++) {
- matrix[r][c] = counter++;
- }
- }
- }
- for (int r = 0; r < n; r++) {
- for (int c = 0; c < n; c++) {
- cout << matrix[r][c] << ' ';
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement