Alx09

Untitled

Feb 26th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <queue>
  4. #include <cstring>
  5. using namespace std;
  6. int n,m;
  7. string Map[101][101],cartela;
  8.  
  9. queue < pair < int, int > > coada;
  10. int startx,starty,stopx,stopy;
  11. int di[]={ -1, 0, 1, 0};
  12. int dj[]={ 0, 1, 0, -1};
  13. short int c,nr = 0;
  14. int Map2[101][101];
  15. void citire()
  16. {
  17. ifstream f("barlog.in");
  18. f >> c;
  19. f >> n >> m;
  20. for (int i = 1 ;i <=n ; i++)
  21. for (int j=1; j <= m ; j++) f >> Map[i][j];
  22.  
  23. f >> startx >> starty;
  24. coada.push(make_pair(startx,starty));
  25. Map2[startx][starty]=1;
  26. f >> cartela;
  27. f.close();
  28. }
  29. bool ok(int i, int j)
  30. {
  31. if (i < 1 || j < 1 || j > m || i > n) return false;
  32.  
  33. return true;
  34. }
  35.  
  36. bool ok2(int i,int j)
  37. {
  38.  
  39. unsigned int st = 0 , dr = 0;
  40. unsigned int n = Map[i][j].size(), m = cartela.size();
  41.  
  42. while ( st < n && dr < m)
  43. {
  44. if (Map[i][j][st] == cartela[dr])
  45. {
  46. st ++; dr++ ;
  47. }
  48. else dr ++;
  49.  
  50. }
  51. if ( st == n )return true;
  52. return false;
  53. }
  54.  
  55.  
  56. void lee()
  57. {
  58. int i, j,i_urm, j_urm;
  59. while(! coada.empty())
  60. {
  61. i = coada.front().first;
  62. j = coada.front().second;
  63. coada.pop();
  64. for(int directie = 0; directie < 4 ; directie++)
  65. {
  66. i_urm = i + di[directie];
  67. j_urm = j + dj[directie];
  68.  
  69. if(ok(i_urm,j_urm) && ok2(i_urm,j_urm) && Map2[i_urm][j_urm] != 0)
  70. {
  71. nr ++;
  72. Map2[i_urm][j_urm] = Map2[i][j] + 1;
  73. coada.push(make_pair(i_urm,j_urm));
  74.  
  75. }
  76.  
  77. }
  78. }
  79. cout << nr;
  80. }
  81. int main()
  82. { ofstream g("barlog.out");
  83. citire();
  84. lee();
  85.  
  86.  
  87. return 0;
  88.  
  89.  
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment