NOIP 2015 普及组 扫雷游戏


#include 
#include  
#include 
#include 
#include 
#include  
#include 
using namespace std;
const  int  MM=102;
char  lei[MM][MM];
//char  res[MM][MM];
int N ,M;

int jisuan(int i, int j){
      int ans=0;
      if( lei[i][j-1] == '*') ans++;
      if( lei[i][j+1] == '*') ans++;
      if( lei[i-1][j-1] == '*') ans++;
      if( lei[i-1][j] == '*') ans++;
      if( lei[i-1][j+1] == '*') ans++;
      if( lei[i+1][j-1] == '*') ans++;
      if( lei[i+1][j] == '*') ans++;
      if( lei[i+1][j+1] == '*') ans++;
      return ans;
}


int main()
{
      cin>> N>>M;
      for(int i=0;i<=N+1; i++){
         for(int j=0;j<=M+1;j++){
              lei[i][j]='?';
            }
      }
      for(int i=1;i<=N; i++){
         for(int j=1;j<=M;j++){
              cin >> lei[i][j];
         }
      }

     for(int i=1;i<=N; i++){
         for(int j=1;j<=M;j++){
             if( lei[i][j]=='*') cout << "*";
             else cout<< jisuan(i,j);
         }
         cout << endl;
     }

    return 0;
}

你可能感兴趣的:(信息学奥赛(NOIP))