Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string input() {
- string start = "";
- while (!cin.eof()) {
- string str;
- cin >> str;
- if ((int)str[str.length() - 1] == 0) {
- str = str.substr(0, str.length() - 1);
- start += str;
- break;
- }
- start += str;
- }
- return start;
- }
- bool check(string start) {
- if (isalpha(start[0]) && isalpha(start[start.length() - 1]))
- return true;
- else
- return false;
- }
- string rule_1(string start) {
- string res = "";
- for (int i = 0; i < start.length(); i++) {
- if ((int)start[i] <= 57 && (int)start[i] >= 49)
- res += (char)((int)start[i] + 48);
- else
- res += start[i];
- }
- return res;
- }
- string rule_2(string start) {
- string res = "";
- char x = start[0];
- res += x;
- for (int i = 1; i < start.length(); i++) {
- if (!(start[i] == x))
- res += start[i];
- x = start[i];
- }
- return res;
- }
- int main() {
- string start = input();
- string res;
- if (check(start))
- res = rule_1(start);
- else
- res = rule_2(start);
- cout << start << endl << res << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment