fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. int main()
  6. {
  7. string values;
  8. getline(cin, values);
  9. string Template;
  10. getline(cin, Template);
  11. string value, placeholder;
  12. int comma, here;
  13. comma = values.find(',');
  14. for (;;)
  15. {
  16. comma = values.find(',');
  17. if (comma == string::npos) break;
  18. placeholder = values.substr(0, comma).substr(0, values.find('='));
  19. value = values.substr(0, values.find(',')).substr(values.find('=') + 1);
  20. for (;;)
  21. {
  22. here = Template.find("[" + placeholder + "]");
  23. if (here == string::npos) break;
  24. Template.replace(here, placeholder.size() + 2, value, 0, value.size());
  25. }
  26. values.erase(0, comma + 1);
  27. }
  28. placeholder = values.substr(0, values.find('='));
  29. value = values.substr(values.find('=') + 1);
  30. for (;;)
  31. {
  32. here = Template.find("[" + placeholder + "]");
  33. if (here == string::npos) break;
  34. Template.replace(here, placeholder.size() + 2, value, 0, value.size());
  35. }
  36. cout << Template << "\n";
  37. return 0;
  38. }
Success #stdin #stdout 0s 4384KB
stdin
person=Paul,action=strolls around,place=the park
[person] [action] [place]
stdout
Paul strolls around the park