Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. string chipher(string s)
  10. {
  11. string ans;
  12. int mark = 1;
  13. for (int i = 1; i < s.size(); ++i)
  14. {
  15. if (s[i - 1] != s[i])
  16. {
  17. ans.push_back(s[i - 1]);
  18. if (i == s.size() - 1)
  19. {
  20. ans.push_back(s[i]);
  21. }
  22. }
  23. else
  24. {
  25. int cnt = 1;
  26. while (i < s.size() && s[i - 1] == s[i])
  27. {
  28. ++cnt, ++i;
  29. }
  30. if (cnt % 2 != 0)
  31. {
  32. ans.push_back(s[i - 1]);
  33. }
  34. ++mark;
  35. }
  36. }
  37. if (mark != 1)
  38. {
  39. chipher(ans);
  40. }
  41. else
  42. {
  43. string trueans = ans;
  44. return trueans;
  45. }
  46. }
  47.  
  48. int main()
  49. {
  50. string s;
  51. cin >> s;
  52.  
  53. s = chipher(s);
  54. for (int i = 0; i < s.size(); ++i)
  55. {
  56. cout << s[i];
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement