Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- ifstream in("minesweeper.in");
- ofstream out("minesweeper.out");
- int A[101][101],B[101][101],n,l,c;
- int dy[]= {0,-1,-1,-1,0,0,1,1,1};
- int dx[]= {0,-1,0,1,-1,1,-1,0,1};
- void citire()
- {
- in>>n>>l>>c;
- for(int i=1; i<=n; i++)
- for(int j=1; j<=n; j++)
- {
- in>>A[i][j];
- B[i][j]=A[i][j];
- }
- }
- void sweeper()
- {
- for(int i=1; i<=n; i++)
- for(int j=1; j<=n; j++)
- if(A[i][j]==-1)
- {
- for(int yeet=1; yeet<=8; yeet++)
- if(A[i+dy[yeet]][j+dx[yeet]]!=-1)
- B[i+dy[yeet]][j+dx[yeet]]++;
- }
- }
- void minisweeper()
- {
- if(A[l][c]==-1)
- {
- for(int i=1; i<=n; i++)
- {
- for(int j=1; j<=n; j++)
- cout<<setw(2)<<B[i][j]<<' ';
- cout<<endl;
- }
- cout<<endl;
- }
- else
- {
- int nr=0;
- for(int yeet=1; yeet<=8; yeet++)
- {
- if(A[l+dy[yeet]][c+dx[yeet]]==-1)
- nr++;
- }
- if(nr!=0)
- {
- A[l][c]=nr;
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n;j++)
- if(i!=l || j!=c) cout<<setw(2)<<-2<<' ';
- else cout<<setw(2)<<A[l][c]<<' ';
- cout<<endl;
- }
- }
- else
- {
- }
- }
- }
- void Afiseaza_ma_maestre()
- {
- for(int i=1; i<=n; i++)
- {
- for(int j=1; j<=n; j++)
- cout<<setw(2)<<B[i][j]<<' ';
- cout<<endl;
- }
- cout<<endl;
- }
- int main()
- {
- citire();
- sweeper();
- Afiseaza_ma_maestre();
- cout<<endl;
- minisweeper();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement