Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. ifstream in("minesweeper.in");
  8. ofstream out("minesweeper.out");
  9.  
  10. int A[101][101],B[101][101],n,l,c;
  11.  
  12. int dy[]= {0,-1,-1,-1,0,0,1,1,1};
  13. int dx[]= {0,-1,0,1,-1,1,-1,0,1};
  14.  
  15. void citire()
  16. {
  17. in>>n>>l>>c;
  18. for(int i=1; i<=n; i++)
  19. for(int j=1; j<=n; j++)
  20. {
  21. in>>A[i][j];
  22. B[i][j]=A[i][j];
  23. }
  24. }
  25. void sweeper()
  26. {
  27. for(int i=1; i<=n; i++)
  28. for(int j=1; j<=n; j++)
  29. if(A[i][j]==-1)
  30. {
  31. for(int yeet=1; yeet<=8; yeet++)
  32. if(A[i+dy[yeet]][j+dx[yeet]]!=-1)
  33. B[i+dy[yeet]][j+dx[yeet]]++;
  34. }
  35. }
  36. void minisweeper()
  37. {
  38. if(A[l][c]==-1)
  39. {
  40. for(int i=1; i<=n; i++)
  41. {
  42. for(int j=1; j<=n; j++)
  43. cout<<setw(2)<<B[i][j]<<' ';
  44. cout<<endl;
  45. }
  46. cout<<endl;
  47. }
  48. else
  49. {
  50. int nr=0;
  51. for(int yeet=1; yeet<=8; yeet++)
  52. {
  53. if(A[l+dy[yeet]][c+dx[yeet]]==-1)
  54. nr++;
  55. }
  56. if(nr!=0)
  57. {
  58. A[l][c]=nr;
  59. for(int i=1;i<=n;i++)
  60. {
  61. for(int j=1;j<=n;j++)
  62. if(i!=l || j!=c) cout<<setw(2)<<-2<<' ';
  63. else cout<<setw(2)<<A[l][c]<<' ';
  64. cout<<endl;
  65. }
  66. }
  67. else
  68. {
  69.  
  70. }
  71. }
  72. }
  73. void Afiseaza_ma_maestre()
  74. {
  75. for(int i=1; i<=n; i++)
  76. {
  77. for(int j=1; j<=n; j++)
  78. cout<<setw(2)<<B[i][j]<<' ';
  79. cout<<endl;
  80. }
  81. cout<<endl;
  82. }
  83. int main()
  84. {
  85. citire();
  86. sweeper();
  87. Afiseaza_ma_maestre();
  88. cout<<endl;
  89. minisweeper();
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement