fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 1000;
  6.  
  7. bool isLetter(char c) {
  8. return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
  9. }
  10.  
  11. void transformText(char text[]) {
  12. int length = strlen(text), wordPos = 0;
  13. for (int i = 0; i < length; ++i) {
  14. if (isLetter(text[i])) {
  15. if (isLetter(text[i + 1])) {
  16. if (wordPos % 2 == 0) {
  17. char aux = text[i + 1];
  18. text[i + 1] = text[i];
  19. text[i] = aux;
  20. }
  21. } else if (wordPos % 2 == 0) {
  22. text[i] = '0';
  23. }
  24. ++wordPos;
  25. } else {
  26. wordPos = 0;
  27. }
  28. }
  29. }
  30.  
  31. int main() {
  32. char text[MAX_SIZE + 1];
  33. while (cin.getline(text, MAX_SIZE + 1)) {
  34. transformText(text);
  35. cout << text << '\n';
  36. }
  37. }
Success #stdin #stdout 0.01s 5272KB
stdin
Daniel are mere
stdout
aDinle ra0 emer