Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- int a, b, a2=1, b2=1;
- char c;
- char mas[102][102];
- //----------------------------------------------------------------------
- void DrawMas()
- {
- for(int i=1; i<=a; i++)
- {
- for(int j=1; j<=b; j++)
- {
- cout << mas[i][j] << " ";
- }
- cout << endl;
- }
- }
- //----------------------------------------------------------------------
- char GetNumber(int i, int j)
- {
- int num = 0;
- char nux;
- if(mas[i-1][j] == '*') num++;
- if(mas[i+1][j] == '*') num++;
- if(mas[i][j-1] == '*') num++;
- if(mas[i][j+1] == '*') num++;
- if(mas[i-1][j-1] == '*') num++;
- if(mas[i-1][j+1] == '*') num++;
- if(mas[i+1][j-1] == '*') num++;
- if(mas[i+1][j+1] == '*') num++;
- nux = num + '0';
- return nux;
- }
- //----------------------------------------------------------------------
- int main()
- {
- cin >> a >> b;
- while (cin >> c)
- {
- mas[a2][b2] = c;
- if (a2 > a) a2 = 1;
- if (b2 >= b)
- {
- b2 = 1;
- a2++;
- continue;
- }
- b2++;
- }
- for(int i=1; i<=a; i++)
- {
- for(int j=1; j<=b; j++)
- {
- if (mas[i][j] != '*')
- {
- mas[i][j] = GetNumber(i, j);
- }
- }
- }
- DrawMas();
- return 0;
- }
Add Comment
Please, Sign In to add comment