Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <string>
- using namespace std;
- string chipher(string s)
- {
- string ans;
- int mark = 1;
- for (int i = 1; i < s.size(); ++i)
- {
- if (s[i - 1] != s[i])
- {
- ans.push_back(s[i - 1]);
- if (i == s.size() - 1)
- {
- ans.push_back(s[i]);
- }
- }
- else
- {
- int cnt = 1;
- while (i < s.size() && s[i - 1] == s[i])
- {
- ++cnt, ++i;
- }
- if (cnt % 2 != 0)
- {
- ans.push_back(s[i - 1]);
- }
- ++mark;
- }
- }
- if (mark != 1)
- {
- chipher(ans);
- }
- else
- {
- string trueans = ans;
- return trueans;
- }
- }
- int main()
- {
- string s;
- cin >> s;
- s = chipher(s);
- for (int i = 0; i < s.size(); ++i)
- {
- cout << s[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement