Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.     string field[8];
  8.     for(int i = 0; i < 8; i++) {
  9.         cin >> field[i];
  10.     }
  11.    
  12.     string newfield[8];
  13.     for(int i = 0; i < 8; i++) {
  14.        
  15.         string stroka = "";
  16.         for(int j = 0; j < 8; j++) {
  17.             int count = 0;
  18.             if(field[i][j] == '*') {
  19.                 stroka += '*';
  20.                 continue;
  21.             }
  22.            
  23.             if(j - 1 >= 0) {
  24.                 if(field[i][j - 1] == '*') {
  25.                     count++;
  26.                 }
  27.             }
  28.            
  29.             if(j + 1 < 8) {
  30.                 if(field[i][j + 1] == '*')
  31.                     count++;
  32.             }
  33.            
  34.             if(i - 1 >= 0) {
  35.                 if(j - 1 >= 0) {
  36.                     if(field[i - 1][j - 1] == '*') {
  37.                         count++;
  38.                     }
  39.                 }
  40.                
  41.                 if(field[i - 1][j] == '*') {
  42.                     count++;
  43.                 }
  44.                
  45.                 if(j + 1 < 8) {
  46.                     if(field[i - 1][j + 1] == '*') {
  47.                         count++;
  48.                     }
  49.                 }
  50.             }
  51.            
  52.             if(i + 1 < 8) {
  53.                 if(j - 1 >= 0) {
  54.                     if(field[i + 1][j - 1] == '*') {
  55.                         count++;
  56.                     }
  57.                 }
  58.                
  59.                 if(field[i + 1][j] == '*') {
  60.                     count++;
  61.                 }
  62.                
  63.                 if(j + 1 < 8) {
  64.                     if(field[i + 1][j + 1] == '*') {
  65.                         count++;
  66.                     }
  67.                 }
  68.             }
  69.            
  70.             stroka += count + '0';
  71.         }
  72.        
  73.         newfield[i] = stroka;
  74.     }
  75.    
  76.    
  77.     for(int i = 0; i < 8; i++) {
  78.         cout << newfield[i] << endl;
  79.     }
  80.    
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement