fork(3) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <map>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. map<string, string> interpolate = { { "F"s, "a && b && c"s }, { "H"s, "p ^ 2 + w"s }, { "K"s, "H > 10 || e < 5"s }, { "J"s, "F && !K"s } };
  11.  
  12. for(const auto& i : interpolate) for_each(begin(interpolate), end(interpolate), [&](auto& it){ for(auto pos = it.second.find(i.first); pos != string::npos; pos = it.second.find(i.first, pos)) it.second.replace(pos, i.first.size(), '(' + i.second + ')'); });
  13.  
  14. for(const auto& i : interpolate) cout << i.first << " : " << i.second << endl;
  15. }
Success #stdin #stdout 0s 15248KB
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