Advertisement
ilnazEPTA

Untitled

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