Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string str;
- getline(cin, str);
- int startIndex = 0, replacedLength = 0;
- for (size_t i = 1; i <= str.length(); i++) {
- if (str[startIndex] != str[i]) {
- startIndex++;
- replacedLength = i - startIndex;
- str.replace(startIndex, replacedLength, "");
- i = startIndex;
- }
- }
- cout << str << endl;
- return 0;
- }
- ИЛИ:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string str;
- getline(cin, str);
- int startIndex = 0, replacedLength = 0;
- for (size_t i = 1; i <= str.length(); i++) {
- if (str[startIndex] != str[i]) {
- startIndex++;
- replacedLength = i - startIndex;
- str.erase(startIndex, replacedLength);
- i = startIndex;
- }
- }
- cout << str << endl;
- return 0;
- }
- ИЛИ:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string str, result;
- getline(cin, str);
- result = str[0];
- for (size_t i = 1; i < str.length(); i++) {
- if (result[result.length() - 1] != str[i]) {
- result += str[i];
- }
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement