Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- string s, res = "";
- char m;
- cout << "enter m:" << endl;
- cin >> m;
- cout << "enter s: " << endl;
- cin >> s;
- char actualSymb = s[1], prevSymb = s[0];
- if (m == 'p') {
- int counter = 1;
- for (int i = 1; s[i]; i++) {
- actualSymb = s[i];
- if (actualSymb == prevSymb)
- counter++;
- else {
- res += prevSymb;
- if (counter > 1)
- res += (counter + '0');
- counter = 1;
- prevSymb = actualSymb;
- }
- }
- if (counter > 1) {
- res += actualSymb;
- if (counter > 1)
- res += (counter + '0');
- counter = 1;
- }
- else {
- res += actualSymb;
- }
- }
- else if (m == 'u') {
- for (int i = 1; s[i]; i++) {
- actualSymb = s[i];
- if (actualSymb > '1' && actualSymb <= '9')
- for (int j = 0; j < actualSymb - '0'; j++)
- res += prevSymb;
- else {
- res += actualSymb;
- prevSymb = actualSymb;
- }
- }
- }
- cout << res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement