Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <memory>
- using namespace std;
- int main() {
- int rows, columns;
- cin >> rows >> columns;
- cin.ignore();
- unique_ptr<unique_ptr<int[]>[]> matrix = make_unique<unique_ptr<int[]>[]>(rows);
- for (int i = 0; i < rows; i++) {
- matrix[i] = make_unique<int[]>(columns);
- }
- string line;
- for (int row = 0; row < rows; row++) {
- getline(cin, line);
- for (int col = 0; col < line.length(); col++) {
- if (line[col] == '!') {
- for (int r = max(row - 1, 0); r <= min(row + 1, rows - 1); r++) {
- for (int c = max(col - 1, 0); c <= min(col + 1, columns - 1); c++) {
- matrix[r][c]++;
- }
- }
- }
- }
- }
- for (int i = 0; i < rows; i++) {
- for (int j = 0; j < columns; j++) {
- cout << matrix[i][j];
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement