fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <boost/utility/string_ref.hpp>
  4.  
  5. using StringVec = std::vector<std::string>;
  6.  
  7. bool isConcatable(const StringVec& l, boost::string_ref s) {
  8. if(s.empty())
  9. return true;
  10.  
  11. for(auto& item : l) {
  12. if(s.starts_with(item)) {
  13. if(isConcatable(l, s.substr(item.length()))) {
  14. return true;
  15. }
  16. }
  17. }
  18. return false;
  19. }
  20.  
  21. int main(int argc, char *argv[]) {
  22. StringVec l = {"ca", "at"};
  23. std::string s = "caat";
  24.  
  25. std::cout << isConcatable(l,s);
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
1