fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1234;
  4. #define mp make_pair
  5. char g[N][N];
  6. int len, X, Y;
  7. set <string> li;
  8. void solve(int x, int y, string s){
  9. if (g[x][y] == '*' || x < 1 || y < 1 || x > X || y > Y)
  10. return ;
  11. if (s.size() == len){
  12. li.insert(s);
  13. return ;
  14. }
  15. s += g[x][y];
  16. solve(x+1, y, s);
  17. solve(x-1, y, s);
  18. solve(x, y+1, s);
  19. solve(x, y-1, s);
  20. }
  21. int main()
  22. {
  23. string s;
  24. cin >> X >> Y;
  25. for (int i = 1; i<=X; i++){
  26. cin >> s;
  27. for(int j = 1; j<=Y; j++)
  28. g[i][j] = s[j-1];
  29. }
  30. int x, y, l;
  31. cin >> len >> x >> y;
  32. solve(x, y, "");
  33. for (auto e : li)
  34. cout << e << endl;
  35. return 0;
  36. }
Success #stdin #stdout 0s 4764KB
stdin
4 7
qwertyu
iopasdf
ghjklzx
cvbnm**
3 1 1
stdout
qig
qio
qiq
qwe
qwo
qwq