Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <vector>
- std::vector <std::vector<char>> get2DMatrix() {
- std::vector <std::vector<char>> output;
- std::string lineInput;
- getline(std::cin, lineInput);
- std::stringstream str(lineInput);
- int token;
- std::vector<int> size2D;
- while (str >> token) {
- size2D.push_back(token);
- }
- for (int i = 0; i < size2D[0]; i++) {
- getline(std::cin, lineInput);
- str.clear();
- str.str(lineInput);
- char c;
- std::vector<char> intLine;
- while (str >> c) {
- intLine.push_back(c);
- }
- output.push_back(intLine);
- }
- return output;
- }
- void printMatrix(std::vector <std::vector<char>>& matrix) {
- int xLength = matrix.size();
- int yLength = matrix[0].size();
- for (size_t i = 0; i < xLength; i++)
- {
- for (size_t j = 0; j < yLength; j++)
- {
- std::cout << matrix[i][j] << ' ';
- }
- std::cout << "\n";
- }
- }
- void paintChar(char c, int y, int x, std::vector <std::vector<char>>& matrix) {
- int xLength = matrix[0].size();
- int yLength = matrix.size();
- char change = matrix[x][y];
- for (int i = x; i < xLength; i++) {
- for (int j = y; j < yLength; j++) {
- if (change == matrix[j][i]) matrix[j][i] = c;
- else break;
- }
- for (int j = y-1; j >= 0; j--) {
- if (change == matrix[j][i] || c == matrix[j][i]) matrix[j][i] = c;
- else break;
- }
- }
- for (int i = x-1; i >=0; i--) {
- for (int j = y; j < yLength; j++) {
- if (change == matrix[j][i]) matrix[j][i] = c;
- else break;
- }
- for (int j = y - 1; j >= 0; j--) {
- if (change == matrix[j][i] ||c == matrix[j][i] ) matrix[j][i] = c;
- else break;
- }
- }
- }
- int main()
- {
- auto matrix = get2DMatrix();
- char c;
- int x, y;
- std::cin >> c >> x >> y;
- paintChar(c, y, x, matrix);
- printMatrix(matrix);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement