Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define star -999
  5.  
  6.  
  7. void mine(int row,int column,int test)
  8. {
  9. int **arr = new int*[row];
  10. for(int i=0; i<row; i++) arr[i] = new int[column];
  11. for(int i=0; i<row; i++)
  12. {
  13. for(int j=0; j<column; j++) arr[i][j] =0;
  14. }
  15. for(int r=0; r<row; r++)
  16. {
  17. for(int c=0; c<column; c++)
  18. {
  19. char ch;
  20. cin>>ch;
  21. if(ch=='.') continue;
  22. else if(ch=='*')
  23. {
  24. int i=r;
  25. int j=c;
  26. arr[i][j] =star;
  27. if((i>=0 && i<row)&&(j-1>=0 && j-1<column) && (arr[i][j-1] != star )) arr[i][j-1]++;
  28. if((i>=0 && i<row)&&(j+1>=0 && j+1<column) && (arr[i][j+1] !=star)) arr[i][j+1]++;
  29. if((i-1>=0 && i-1<row)&&(j>=0 && j<column) && (arr[i-1][j] !=star)) arr[i-1][j]++;
  30. if((i-1>=0 && i-1<row)&&(j-1>=0 && j-1<column) &&(arr[i-1][j-1]!=star)) arr[i-1][j-1]++;
  31. if((i-1>=0 && i-1<row)&&(j+1>=0 && j+1<column) &&(arr[i-1][j+1] !=star) ) arr[i-1][j+1]++;
  32. if((i+1>=0 && i+1<row)&&(j>=0 && j<column) &&(arr[i+1][j] !=star)) arr[i+1][j]++;
  33. if((i+1>=0 && i+1<row)&&(j-1>=0 && j-1<column) &&(arr[i+1][j-1] !=star)) arr[i+1][j-1]++;
  34. if((i+1>=0 && i+1<row)&&(j+1>=0 && j+1<column) &&(arr[i+1][j+1] !=star)) arr[i+1][j+1]++;
  35. }
  36. }
  37. }
  38. //cout<<endl;
  39. cout<<"Field #"<<test<<":"<<endl;
  40. for(int i=0; i<row; i++)
  41. {
  42. for(int j=0; j<column; j++){
  43. if(arr[i][j]==star) cout<<'*';
  44. else cout<<arr[i][j];
  45. }
  46. cout<<endl;
  47. }
  48. // cout<<endl;
  49. for(int i=0;i<row;i++) delete arr[i];
  50. delete arr;
  51. }
  52.  
  53.  
  54. int main()
  55. {
  56. int n,m,counter=0;
  57. for(int test =1;;test++)
  58. {
  59. cin>>n>>m;
  60. if(n==0 && m==0) break;
  61. counter++;
  62. if (counter > 1) cout << '\n';
  63. mine(n,m,test);
  64. }
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement