fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int xd[5] = {-1, 0 ,0};
  5. int yd[5] = {0, +1, -1};
  6. bool vis[10][10];
  7. char arr[10][10];
  8. int x, y;
  9. vector<string> v;
  10. string s;
  11. int counter;
  12. bool vaild(int i, int j)
  13. {
  14. return i >= 0 && i <x && j >= 0 && j < y;
  15. }
  16. void dfs(int x, int y)
  17. {
  18. vis[x][y] = true;
  19. for(int i=0; i<3; i++)
  20. {
  21. int newx = x + xd[i];
  22. int newy = y + yd[i];
  23. if(arr[newx][newy] == s[0] && !vis[newx][newy])
  24. {
  25. vis[newx][newy] = true;
  26. if(i == 0)
  27. v.push_back("forth");
  28. else if(i == 1)
  29. v.push_back("right");
  30. else
  31. v.push_back("left");
  32. s.erase(s.begin() + 0);
  33. dfs(newx, newy);
  34. }
  35. }
  36. }
  37.  
  38.  
  39. int main()
  40. {
  41. int n; cin >> n;
  42. while(n--)
  43. {
  44. cin >> x;
  45. cin >> y;
  46. s = "IEHOVA#";
  47.  
  48. memset(vis, 0, sizeof(vis));
  49. for(int i=0; i<x; i++)
  50. {
  51. for(int j=0; j<y; j++)
  52. {
  53. cin >> arr[i][j];
  54. }
  55. }
  56.  
  57. for(int i=0; i<y; i++)
  58. {
  59. if(arr[x-1][i] == '@')
  60. {
  61. dfs(x-1, i);
  62. break;
  63. }
  64. }
  65. for(int i=0; i<v.size(); i++)
  66. {
  67. cout << v[i] << " ";
  68. }
  69. cout << endl;
  70. v.clear();
  71.  
  72. }
  73.  
  74.  
  75. return 0;
  76. }
  77.  
Success #stdin #stdout 0.08s 4944KB
stdin
Standard input is empty
stdout