fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. map<string, string> interpolate = { { "F", "a && b && c" }, { "H", "p ^ 2 + w" }, { "K", "H > 10 || e < 5" }, { "J", "F && !K" } };
  9.  
  10. for(map<string, string>::iterator i = interpolate.begin(); i != interpolate.end(); ++i) {
  11. for(map<string, string>::iterator it = interpolate.begin(); it != interpolate.end(); ++it) {
  12. for(string::size_type pos = it->second.find(i->first); pos != string::npos; pos = it->second.find(i->first, pos)) {
  13. it->second.replace(pos, i->first.size(), '(' + i->second + ')');
  14. }
  15. }
  16. }
  17.  
  18. for(map<string, string>::iterator i = interpolate.begin(); i != interpolate.end(); ++i) {
  19. cout << i->first << " : " << i->second << endl;
  20. }
  21. }
Success #stdin #stdout 0s 16072KB
stdin
Standard input is empty
stdout
F : a && b && c
H : p ^ 2 + w
J : (a && b && c) && !((p ^ 2 + w) > 10 || e < 5)
K : (p ^ 2 + w) > 10 || e < 5