Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- typedef unsigned int ui;
- int main() {
- char s[1001] = {}, previous;
- bool flag = false;
- cin.getline(s,1000);
- ui SZ = strlen(s), count = 0;
- for (ui i = 0; i < SZ; ++i) {
- if (SZ == 2 && s[0] == s[1]) {
- cout << s[0] << 2;
- break;
- }
- if (i == 0) {
- if (s[0] != s[1])
- cout << s[0];
- previous = s[i];
- count = 1;
- flag = true;
- continue;
- }
- if (s[i] == previous) {
- ++count;
- }
- if (i == SZ-1 && SZ > 2) {
- if (s[SZ-1] != s[SZ-2]) {
- cout << previous;
- if (count != 1)
- cout << count;
- count = 1;
- cout << s[i];
- if (count != 1)
- cout << count;
- break;
- }
- cout << s[i];
- if (count != 1)
- cout << count;
- break;
- }
- if (i == SZ-1 && SZ == 2) {
- cout << s[i];
- }
- if (s[i] != previous && !flag) {
- cout << previous;
- if (count != 1)
- cout << count;
- count = 1;
- }
- flag = false;
- previous = s[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement