Advertisement
HjHimansh

Untitled

Oct 7th, 2023 (edited)
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8.  
  9. int main() {
  10. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  11. string s;
  12. cin >> s;
  13. string res = "";
  14. res += s[0];
  15.  
  16. for(long i = 1; i < s.size(); i++) {
  17. long count = 1;
  18. if(s[i - 1] != s[i])
  19. res += s[i];
  20. while(i<s.size() && s[i] == s[i - 1]) {
  21. count++;
  22. i++;
  23. }
  24. if(count != 1) {
  25. res += to_string(count);
  26. i--;
  27. }
  28. }
  29. cout << res << endl;
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement