Advertisement
ioana_martin98

Untitled

Nov 20th, 2022 (edited)
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. char s[256];
  7.  
  8. void elim(int i, int k)
  9. {
  10.     while (s[i] != '\0')
  11.     {
  12.         s[i - k] = s[i];
  13.         i++;
  14.     }
  15.     s[i - k] = '\0';
  16. }
  17. int main()
  18. {
  19.     cin >> s;
  20.     int i = 0, k = 0;
  21.     for (i = 0; i < strlen(s); i++)
  22.     {
  23.         if (tolower(s[i]) == tolower(s[i - 1]))
  24.             k+=1;
  25.         else
  26.         {
  27.             if (k != 0)
  28.             {
  29.                 elim(i, k+1);
  30.                 i = 0;
  31.             }
  32.             k = 0;
  33.         }
  34.         if (s[i] == '\0')
  35.         {
  36.             s[i] = ' ';
  37.             s[i + 1] = '\0';
  38.         }
  39.     }
  40.  
  41.     cout << s;
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement