Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define star -999
- void mine(int row,int column,int test)
- {
- int **arr = new int*[row];
- for(int i=0; i<row; i++) arr[i] = new int[column];
- for(int i=0; i<row; i++)
- {
- for(int j=0; j<column; j++) arr[i][j] =0;
- }
- for(int r=0; r<row; r++)
- {
- for(int c=0; c<column; c++)
- {
- char ch;
- cin>>ch;
- if(ch=='.') continue;
- else if(ch=='*')
- {
- int i=r;
- int j=c;
- arr[i][j] =star;
- if((i>=0 && i<row)&&(j-1>=0 && j-1<column) && (arr[i][j-1] != star )) arr[i][j-1]++;
- if((i>=0 && i<row)&&(j+1>=0 && j+1<column) && (arr[i][j+1] !=star)) arr[i][j+1]++;
- if((i-1>=0 && i-1<row)&&(j>=0 && j<column) && (arr[i-1][j] !=star)) arr[i-1][j]++;
- if((i-1>=0 && i-1<row)&&(j-1>=0 && j-1<column) &&(arr[i-1][j-1]!=star)) arr[i-1][j-1]++;
- if((i-1>=0 && i-1<row)&&(j+1>=0 && j+1<column) &&(arr[i-1][j+1] !=star) ) arr[i-1][j+1]++;
- if((i+1>=0 && i+1<row)&&(j>=0 && j<column) &&(arr[i+1][j] !=star)) arr[i+1][j]++;
- if((i+1>=0 && i+1<row)&&(j-1>=0 && j-1<column) &&(arr[i+1][j-1] !=star)) arr[i+1][j-1]++;
- if((i+1>=0 && i+1<row)&&(j+1>=0 && j+1<column) &&(arr[i+1][j+1] !=star)) arr[i+1][j+1]++;
- }
- }
- }
- //cout<<endl;
- cout<<"Field #"<<test<<":"<<endl;
- for(int i=0; i<row; i++)
- {
- for(int j=0; j<column; j++){
- if(arr[i][j]==star) cout<<'*';
- else cout<<arr[i][j];
- }
- cout<<endl;
- }
- // cout<<endl;
- for(int i=0;i<row;i++) delete arr[i];
- delete arr;
- }
- int main()
- {
- int n,m,counter=0;
- for(int test =1;;test++)
- {
- cin>>n>>m;
- if(n==0 && m==0) break;
- counter++;
- if (counter > 1) cout << '\n';
- mine(n,m,test);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement