Alx09

Untitled

Feb 26th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 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. short int c;
  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. size_t poz = cartela.find(Map[i][j]);
  34. if (poz == string::npos) return false;
  35.  
  36. return true;
  37. }
  38.  
  39. void afisare()
  40. {
  41. ofstream g("barlog.out");
  42. for (int i=1; i<=n;i++)
  43. {
  44. for(int j=1; j <=m; j++)
  45. g <<Map2[i][j]<<' ';
  46.  
  47. g <<'\n';
  48. }
  49. }
  50. void lee()
  51. { string caut;
  52. int i, j,i_urm, j_urm;
  53. while(! coada.empty())
  54. {
  55. i = coada.front().first;
  56. j = coada.front().second;
  57. coada.pop();
  58. for(int directie=0;i < 4 ;i++)
  59. {
  60. i_urm = i + di[directie];
  61. j_urm = j + dj[directie];
  62.  
  63. if(ok(i_urm,j_urm) )
  64. {
  65.  
  66. Map2[i_urm][j_urm] = Map2[i][j] + 1;
  67. coada.push(make_pair(i_urm,j_urm));
  68.  
  69. }
  70. }
  71. }
  72. }
  73. int main()
  74. {
  75. citire();
  76. lee();
  77. afisare();
  78.  
  79.  
  80.  
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment