Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <sstream>
- #include <string>
- std::string from_pattern(std::string pattern) {
- int i{0};
- std::map<char, int> m;
- std::ostringstream s;
- for (char c : pattern) {
- auto t = m.find(c);
- if (t != m.end()) {
- s << '\\' << t->second;
- continue;
- }
- t = m.begin();
- if (t != m.end()) {
- s << "(?!\\" << t->second;
- while (++t != m.end())
- s << "|\\" << t->second;
- s << ")";
- }
- s << "(.)";
- m.emplace(c, ++i);
- }
- return s.str();
- }
- int main() {
- std::string line;
- while (std::getline(std::cin, line))
- std::cout << line << " -> " << from_pattern(line) << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement