SHARE
TWEET

barlog

Nita_Cristian Feb 27th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("barlog.in");
  6. ofstream fout("barlog.out");
  7.  
  8. int v, n, m, si, sj, zone, iesiri;
  9. string a[100][100], cod;
  10.  
  11. bool margine(int i, int j)
  12. {
  13.     return i == n || i == 1 || j == m || j == 1;
  14. }
  15.  
  16. bool cod_bun(string )
  17.  
  18. void fil(int i, int j)
  19. {
  20.     queue<pair<int, int>> q;
  21.     q.push({i, j});
  22.  
  23.     while(!q.empty())
  24.     {
  25.         i = q.front().first();
  26.         j = q.front().second();
  27.         q.pop();
  28.  
  29.         zone++;
  30.         if(margine(i, j))
  31.             iesire++;
  32.  
  33.         if(cod_bun(a[i][j], cod))
  34.         {
  35.             q.push({i, j+1});
  36.             q.push({i, j-1});
  37.             q.push({i+1, j});
  38.             q.push({i-1, j});
  39.         }
  40.     }
  41. }
  42.  
  43. int main()
  44. {
  45.     fin >> v;
  46.     fin >> n >> m;
  47.     for(int i = 1; i <= n; i++)
  48.     {
  49.         for(int j = 1; j <= m; j++)
  50.         {
  51.             fin >> a[i][j];
  52.         }
  53.     }
  54.     fin >> si >> sj >> cod;
  55.  
  56.     fil(si, sj);
  57.  
  58.     fout << zone << ' ' << iesiri;
  59.  
  60.     fin.close();
  61.     fout.close();
  62.  
  63.     return 0;
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top