Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <sstream>
  4. #include <string>
  5.  
  6. std::string from_pattern(std::string pattern) {
  7. int i{0};
  8. std::map<char, int> m;
  9. std::ostringstream s;
  10. for (char c : pattern) {
  11. auto t = m.find(c);
  12. if (t != m.end()) {
  13. s << '\\' << t->second;
  14. continue;
  15. }
  16. t = m.begin();
  17. if (t != m.end()) {
  18. s << "(?!\\" << t->second;
  19. while (++t != m.end())
  20. s << "|\\" << t->second;
  21. s << ")";
  22. }
  23. s << "(.)";
  24. m.emplace(c, ++i);
  25. }
  26. return s.str();
  27. }
  28.  
  29. int main() {
  30. std::string line;
  31. while (std::getline(std::cin, line))
  32. std::cout << line << " -> " << from_pattern(line) << std::endl;
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement