fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 2000;
  6.  
  7. bool isLetter(char a) {
  8. return (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z');
  9. }
  10.  
  11. void changeWord(char a[]) {
  12. int n = strlen(a);
  13. char b[MAX_SIZE];
  14. if (n % 2 == 0) {
  15. int mid = n / 2;
  16. for (int i = 0; i < n; ++i) {
  17. b[i] = a[(i + mid) % n];
  18. }
  19. } else {
  20. int mid = n / 2;
  21. for (int i = 0; i < n; ++i) {
  22. if (i == mid) {
  23. b[i] = a[i];
  24. } else {
  25. b[i] = a[(i + mid + 1) % n];
  26. }
  27. }
  28. }
  29. b[n] = '\0'; // Terminator de șir
  30. strcpy(a, b);
  31. }
  32.  
  33. void makeInversRow(char a[]) {
  34. int n = strlen(a);
  35. int j = 0;
  36. char word[MAX_SIZE];
  37. bool inWord = false;
  38.  
  39. for (int i = 0; i < n; ++i) {
  40. if (isLetter(a[i])) {
  41. if (!inWord) {
  42. j = 0;
  43. inWord = true;
  44. }
  45. word[j++] = a[i];
  46. } else {
  47. if (inWord) {
  48. word[j] = '\0';
  49. changeWord(word);
  50. cout << word;
  51. inWord = false;
  52. }
  53. cout << a[i];
  54. }
  55. }
  56.  
  57. if (inWord) {
  58. word[j] = '\0';
  59. changeWord(word);
  60. cout << word;
  61. }
  62. }
  63.  
  64. int main() {
  65. char row[MAX_SIZE];
  66. while (cin.getline(row, MAX_SIZE)) {
  67. makeInversRow(row);
  68. cout << endl; // Adaugă o linie nouă după fiecare linie procesată
  69. }
  70. return 0;
  71. }
Success #stdin #stdout 0s 5272KB
stdin
Ana, dar si Maria invata sa programeze pe WellCode!!
stdout
ann, raa is iarar atainv as amezeprogr ep CodeWell!!