You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.1 KiB

  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. #include <unordered_set>
  5. #include <vector>
  6. bool isConcat(std::string &s, int pos, std::vector<std::string> &v,
  7. std::unordered_set<int> st) {
  8. if (st.size() == v.size()) return 1;
  9. for (int i = 0; i < v.size(); ++i) {
  10. bool ok = 1;
  11. if (st.find(i) != st.end()) continue;
  12. if (v[i].size() > s.size() - pos) continue;
  13. for (int j = 0; j < v[i].size(); ++j) {
  14. if (s[pos + j] != v[i][j]) {
  15. ok = 0;
  16. break;
  17. }
  18. }
  19. if (ok) {
  20. st.insert(i);
  21. if (isConcat(s, pos + v[i].size(), v, st)) return 1;
  22. st.erase(i);
  23. }
  24. }
  25. return 0;
  26. }
  27. int main() {
  28. std::ifstream in;
  29. std::ofstream out;
  30. in.open("input.txt");
  31. out.open("output.txt");
  32. std::string s, temp;
  33. in >> s;
  34. std::vector<std::string> v;
  35. while (in >> temp) {
  36. v.push_back(temp);
  37. }
  38. for (int i = 0; i < s.size(); ++i) {
  39. std::unordered_set<int> st;
  40. if (isConcat(s, i, v, st)) out << i << ' ';
  41. }
  42. }