fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. void modify(string& s) {
  5. string res;
  6. size_t i = 0;
  7. while (i < s.size()) {
  8. while (i < s.size() && s[i] == ' ') ++i;
  9. if (i >= s.size()) break;
  10. size_t j = i;
  11. while (j < s.size() && s[j] != ' ') ++j;
  12. string w = s.substr(i, j - i);
  13. bool lettersOnly = true;
  14. bool symbolsOnly = true;
  15. for (char c : w) {
  16. if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) lettersOnly = false;
  17. if (!(c == '&' || c == '$' || c == '%')) symbolsOnly = false;
  18. }
  19. if (!symbolsOnly) {
  20. string t;
  21. for (char c : w) {
  22. if (c == '&') t.push_back('*');
  23. else if (c == '%') { t.push_back('!'); t.push_back('!'); }
  24. else if (c == '$');
  25. else t.push_back(c);
  26. }
  27. if (lettersOnly) {
  28. for (char& c : t) if (c >= 'a' && c <= 'z') c = char(c - ('a' - 'A'));
  29. }
  30. if (!t.empty()) {
  31. if (!res.empty()) res.push_back(' ');
  32. res += t;
  33. }
  34. }
  35. i = j;
  36. }
  37. s = res;
  38. }
  39. int main() {
  40. string s;
  41. if (!getline(cin, s)) return 0;
  42. modify(s);
  43. cout << s;
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5316KB
stdin
111 & 000 equeals 0
stdout
111 000 EQUEALS 0