fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_LENGTH = 2000;
  6.  
  7. int is_letter (char text) {
  8. int is_letter = 0;
  9. if ((text >= 'A' && text <= 'Z') || (text >= 'a' && text <= 'z')) {
  10. is_letter = 1;
  11. }
  12. return is_letter;
  13. }
  14.  
  15. int main() {
  16. char text[MAX_LENGTH + 1];
  17. while (!cin.eof()) {
  18. cin.getline(text,MAX_LENGTH + 1);
  19. int text_length = strlen(text);
  20. int word_start = - 1, word_end = 0;
  21. for (int i = 0; i <= text_length; ++i) {
  22. if (is_letter(text[i]) == 1 && word_start < 0) {
  23. word_start = i;
  24. } else if (is_letter(text[i]) == 0 && word_start >= 0) {
  25. word_end = i - 1;
  26. char aux = '0';
  27. int k, word_length = word_end - word_start + 1;
  28. if (word_length % 2 == 0) {
  29. k = 0;
  30. } else {
  31. k = 1;
  32. }
  33. cout << word_start << " " << word_end << " " << word_length << " | ";
  34. for (int j = 0; j < word_length / 2; ++j) {
  35. aux = text[word_start + j];
  36. text[word_start + j] = text[word_start + word_length / 2 + k + j];
  37. text[word_start + word_length / 2 + k + j] = aux;
  38. }
  39. word_start = - 1;
  40. word_end = 0;
  41. }
  42. }
  43. cout << text << "\n";
  44. }
  45. }
Success #stdin #stdout 0.01s 5452KB
stdin
alor
stdout
0 3 4 | oral