d_skat

Untitled

May 13th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string input() {
  7.     string start = "";
  8.     while (!cin.eof()) {
  9.         string str;
  10.         cin >> str;
  11.         if ((int)str[str.length() - 1] == 0) {
  12.             str = str.substr(0, str.length() - 1);
  13.             start += str;
  14.             break;
  15.         }
  16.         start += str;
  17.     }
  18.     return start;
  19. }
  20.  
  21. bool check(string start) {
  22.     if (isalpha(start[0]) && isalpha(start[start.length() - 1]))
  23.         return true;
  24.     else
  25.         return false;
  26. }
  27.  
  28. string rule_1(string start) {
  29.     string res = "";
  30.     for (int i = 0; i < start.length(); i++) {
  31.         if ((int)start[i] <= 57 && (int)start[i] >= 49)
  32.             res += (char)((int)start[i] + 48);
  33.         else
  34.             res += start[i];
  35.     }
  36.     return res;
  37. }
  38.  
  39. string rule_2(string start) {
  40.     string res = "";
  41.     char x = start[0];
  42.     res += x;
  43.     for (int i = 1; i < start.length(); i++)
  44.         if (!(start[i] == x))
  45.             res += start[i];
  46. }
  47.  
  48. int main() {
  49.     string start = input();
  50.     string res;
  51.     if (check(start))
  52.         res = rule_1(start);
  53.     else
  54.         res = rule_2(start);
  55.     cout << start << endl << res << endl;
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment