fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_map>
  4.  
  5. typedef std::pair<std::string::const_iterator,std::string::const_iterator> FindType;
  6.  
  7. FindType findSubKey(std::string &S) {
  8. auto a = S.find_first_of('a');
  9. auto b = S.find_last_of('f');
  10. std::cout << a << ":" << b <<std::endl;
  11. return {S.begin()+a,S.begin()+b};
  12. }
  13.  
  14. int main () {
  15. std::unordered_map<std::string, int> map = {
  16. {"123",3},
  17. {"123456abcdefx",2},
  18. {"abcde",7},
  19. {"6abcdef",1}
  20. };
  21. std::string bigString = "123abcdefjhk";
  22. std::string::const_iterator subKeyBegin, subKeyEnd;
  23. std::tie(subKeyBegin, subKeyEnd) = findSubKey(bigString);
  24. //////////////////////////////////////////////////////////////////
  25. std::string Tmp = "";
  26. Tmp.reserve(bigString.size());
  27. //////////////////////////////////////////////////////////////////
  28. Tmp.assign(subKeyBegin,subKeyEnd);
  29. std::cout << "\"" << Tmp << "\"" << std::endl;
  30. std::cout << (map.find(Tmp)!=map.end() ? "Нашли":"Не нашли") << std::endl;
  31. return 0;
  32. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
3:8
"abcde"
Нашли