fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 100;
  6.  
  7. bool isLetter(char a) {
  8. if ((a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z')) {
  9. return true;
  10. }
  11. return false;
  12. }
  13.  
  14. void changeWord(char a[]) {
  15. int n = strlen(a);
  16. char b[n];
  17. if (n % 2 == 0) {
  18. int index = n / 2;
  19. for (int i = 0; i < n; ++i) {
  20. b[i] = a[index];
  21. ++index;
  22. if (index == n) {
  23. index = 0;
  24. }
  25. }
  26. } else if (n % 2 != 0) {
  27. int index = n / 2 + 1;
  28. for (int i = 0; i < n; ++i) {
  29. b[i] = a[index];
  30. ++index;
  31. if (index == n) {
  32. index = 0;
  33. ++i;
  34. b[i] = a[n / 2];
  35. }
  36. }
  37. }
  38. b[n] = '\0';
  39. strcpy(a, b);
  40. }
  41.  
  42. void makeInversRow(char a[]) {
  43. int n = strlen(a), j = 0, firstSign = 0;
  44. char word[MAX_SIZE];
  45. for (int i = 0; i < n; ++i) {
  46. if (isLetter(a[i])) {
  47. word[j++] = a[i];//make the word
  48. firstSign = 0;
  49. } else {
  50. if (firstSign == 0) {
  51. changeWord(word);//when is not letter, cout the new word
  52. cout << word;
  53. }
  54. firstSign = 1;
  55. cout << a[i];
  56. j = 0;
  57. }
  58. if (i == n - 1 && isLetter(a[i])) {
  59. changeWord(word);
  60. cout << word;
  61. }
  62. }
  63. }
  64. int main() {
  65. char row[MAX_SIZE];
  66. while (!cin.eof()) {
  67. cin.getline(row, MAX_SIZE);
  68. }
  69. makeInversRow(row);
  70. return 0;
  71. }
Success #stdin #stdout 0s 5284KB
stdin
Invata si tu sa programezi$$
stdout
ataInv Invsia siatuv tuvsaa ameziprogr$$