Advertisement
ilnazEPTA

Untitled

Dec 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. char m;
  8. string s, res;
  9. cout << " Enter string s: " << endl;
  10. getline(cin, s);
  11. cout << " m: " << endl;
  12. cin >> m;
  13.  
  14. char prev = s[0];
  15. char act = s[1];
  16. if (m == 'p')
  17. {
  18.  
  19. int k = 1;
  20. for (int i = 1; s[i]; i++)
  21. {
  22. act = s[i];
  23. if (act == prev)
  24. k++;
  25. else
  26. {
  27. if (k > 1)
  28. res += (k + '0');
  29. k = 1;
  30. res += prev;
  31. prev = act;
  32. }
  33. }
  34. if (k > 1)
  35. {
  36. res += (k + '0');
  37. k = 1;
  38. res += act;
  39. }
  40. else
  41. {
  42. res += act;
  43. }
  44. }
  45. else
  46. {
  47. for (int i = 1; s[i]; i++)
  48. {
  49. act = s[i];
  50. if (prev > '1' && prev <= '9')
  51. {
  52. for (int j = 1; j < prev - '0'; j++)
  53. res += act;
  54. prev = act;
  55. }
  56. else
  57. {
  58. res += prev;
  59. prev = act;
  60. }
  61. }
  62. res += prev;
  63. }
  64.  
  65. cout << res;
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement