fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. void modify(string & s) {
  5. string t;
  6. for (int i = 0; i < s.size(); i++) {
  7. if (s[i] == '&') t += "&&";
  8. else if (s[i] == '$') t += "!";
  9. else if (s[i] == '%') continue;
  10. else t += s[i];
  11. }
  12. s = t;
  13.  
  14. t = "";
  15. int word = 1;
  16. for (int i = 0; i < s.size();) {
  17. while (i < s.size() && s[i] == ' ') { t += s[i]; i++; }
  18. int j = i;
  19. while (j < s.size() && s[j] != ' ') j++;
  20.  
  21. if (word % 2 == 0) t += "***";
  22. else t += s.substr(i, j - i);
  23.  
  24. word++;
  25. i = j;
  26. }
  27. s = t;
  28. }
  29. int main() {
  30. string s;
  31. getline(cin, s);
  32. modify(s);
  33. cout << s;
  34. }
Success #stdin #stdout 0s 5304KB
stdin
apples$ are great%&
stdout
apples! *** great&&