Guest User

Untitled

a guest
Jan 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5. int a, b, a2=1, b2=1;
  6. char c;
  7. char mas[102][102];
  8.  
  9. //----------------------------------------------------------------------
  10. void DrawMas()
  11. {
  12. for(int i=1; i<=a; i++)
  13. {
  14. for(int j=1; j<=b; j++)
  15. {
  16. cout << mas[i][j] << " ";
  17. }
  18.  
  19. cout << endl;
  20. }
  21. }
  22.  
  23. //----------------------------------------------------------------------
  24. char GetNumber(int i, int j)
  25. {
  26. int num = 0;
  27. char nux;
  28.  
  29. if(mas[i-1][j] == '*') num++;
  30. if(mas[i+1][j] == '*') num++;
  31. if(mas[i][j-1] == '*') num++;
  32. if(mas[i][j+1] == '*') num++;
  33. if(mas[i-1][j-1] == '*') num++;
  34. if(mas[i-1][j+1] == '*') num++;
  35. if(mas[i+1][j-1] == '*') num++;
  36. if(mas[i+1][j+1] == '*') num++;
  37.  
  38. nux = num + '0';
  39.  
  40. return nux;
  41. }
  42.  
  43. //----------------------------------------------------------------------
  44. int main()
  45. {
  46. cin >> a >> b;
  47.  
  48. while (cin >> c)
  49. {
  50. mas[a2][b2] = c;
  51.  
  52. if (a2 > a) a2 = 1;
  53. if (b2 >= b)
  54. {
  55. b2 = 1;
  56. a2++;
  57.  
  58. continue;
  59. }
  60.  
  61. b2++;
  62. }
  63.  
  64. for(int i=1; i<=a; i++)
  65. {
  66. for(int j=1; j<=b; j++)
  67. {
  68. if (mas[i][j] != '*')
  69. {
  70. mas[i][j] = GetNumber(i, j);
  71. }
  72. }
  73. }
  74.  
  75. DrawMas();
  76.  
  77. return 0;
  78. }
Add Comment
Please, Sign In to add comment