只有2,8ac,大佬帮忙看看
查看原帖
只有2,8ac,大佬帮忙看看
885309
Tongzi_楼主2023/7/24 22:23
#include <iostream>
using namespace std ;
int main()
{
   int x , y ;
   cin >> x >> y ;
   int a[x+2][y+2] = {0};
   for (int i = 1 ; i <=x ; i++)
   {
       for(int j = 1 ; j <= y ; j++)
       {
           char c ;
           cin >> c ;
           if (c = '*') 
           a[i][j] = 10 ;
       }
   }
   for (int i = 1 ; i <=x ; i++)
   {
       for(int j = 1 ; j <= y ; j++)
       {
           if (a[i][j]==10)
           continue;
           else
           {
               int num = 0 ;
               for(int n = i - 1 ; n <= i + 1 ; n++)
               {
                   for(int m = j - 1 ; m <= j+1 ; m++)
                   {
                       if (a[n][m]=10)
                       num++;
                   }
               }
               a[i][j] = num ;
           }
       }
   }
   for (int i = 1 ; i <=x ; i++)
   {
       for(int j = 1 ; j <= y ; j++)
       {
           if (a[i][j]==10)
           cout << "*" ;
           else
           cout << a[i][j] ;
       }
       cout << endl ;
   }
   return 0 ;
}
2023/7/24 22:23
加载中...