Morass

Minesweeper

Mar 13th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. char matrix[105][105], temp[105];
  7. int main(){
  8.     int n, m, c=1;
  9.     bool space = true;
  10.     while(cin >> n){
  11.         memset(matrix,0,sizeof(matrix));
  12.         cin >> m;
  13.         if(n==0 && m==0)
  14.             return 0;
  15.         for(int i=0; i<n; i++){
  16.             gets(temp);
  17.             cin >> matrix[i];
  18.         }
  19.         if(c>1)
  20.             cout << endl;
  21.         cout << "Field #" << c << ":" << endl;
  22.         int bomb;
  23.         for(int j=0; j<n; j++){
  24.             for(int k=0; k<m; k++){
  25.                 if(matrix[j][k]=='*')
  26.                     cout << "*";
  27.                 else{
  28.                     bomb=0;
  29.                     if(matrix[j-1][k-1]=='*')
  30.                         bomb++;
  31.                     if(matrix[j-1][k]=='*')
  32.                         bomb++;
  33.                     if(matrix[j-1][k+1]=='*')
  34.                         bomb++;
  35.                     if(matrix[j][k-1]=='*')
  36.                         bomb++;
  37.                     if(matrix[j][k+1]=='*')
  38.                         bomb++;
  39.                     if(matrix[j+1][k-1]=='*')
  40.                         bomb++;
  41.                     if(matrix[j+1][k]=='*')
  42.                         bomb++;
  43.                     if(matrix[j+1][k+1]=='*')
  44.                         bomb++;
  45.  
  46.                     cout << bomb;
  47.                 }
  48.             }
  49.             cout << endl;
  50.         }
  51.         c++;
  52.     }
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment