Alx09

Untitled

Feb 26th, 2019
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 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;
  11. int di[]={ -1, 0, 1, 0};
  12. int dj[]={ 0, 1, 0, -1};
  13. int c,nr = 1;
  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. if(Map2[i][j] != 0 ) return false;
  33. return true;
  34. }
  35.  
  36. bool ok2(int i,int j)
  37. {
  38.  
  39. unsigned int st = 0 , dr = 0;
  40.  
  41. unsigned int x = Map[i][j].size(),y = cartela.size() ;
  42.  
  43.  
  44. while ( st < x && dr < y)
  45. {
  46. if (Map[i][j][st] == cartela[dr])
  47. {
  48. st ++;
  49. dr ++;
  50. }
  51. else dr ++;
  52.  
  53. }
  54.  
  55. if ( st == x )return true;
  56. return false;
  57.  
  58. }
  59. void afisare()
  60. {
  61. for (int i=1 ; i <= n ;i++)
  62. {
  63. for (int j = 1; j <= m; j++)
  64. cout << Map2[i][j] << ' ';
  65. cout <<'\n';
  66. }
  67. }
  68.  
  69. void lee()
  70. {
  71. int i, j,i_urm, j_urm;
  72. while(!coada.empty())
  73. {
  74. i = coada.front().first;
  75. j = coada.front().second;
  76. coada.pop();
  77. for(int directie = 0; directie < 4 ; directie ++)
  78. {
  79. i_urm = i + di[directie];
  80. j_urm = j + dj[directie];
  81.  
  82. if(ok(i_urm,j_urm) && ok2(i_urm,j_urm))
  83. {
  84.  
  85.  
  86. Map2[i_urm][j_urm] = Map2[i][j] + 1;
  87. coada.push(make_pair(i_urm,j_urm));
  88.  
  89. }
  90.  
  91. }
  92. }
  93.  
  94.  
  95. }
  96. int main()
  97. { //ofstream g("barlog.out");
  98. citire();
  99. lee();
  100. afisare();
  101.  
  102. return 0;
  103.  
  104.  
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment