Advertisement
Guest User

Untitled

a guest
Jan 15th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <sstream>
  5.  
  6. int main()
  7. {
  8. std::vector<std::string> compressed;
  9. std::string input;
  10. int counter = 1;
  11.  
  12. std::cin >> input;
  13.  
  14. for (int element = 0; element < input.size(); element++)
  15. {
  16. std::string formattedInput;
  17. if (input[element] == input[element + 1] && input[element + 1] != input.size()+1)
  18. {
  19. counter++;
  20. }
  21. else if (input[element] != input[element + 1] && counter == 1)
  22. {
  23. formattedInput += input[element];
  24. compressed.push_back(formattedInput);
  25. counter = 1;
  26. }
  27. else if (input[element] != input[element + 1] && counter == 2)
  28. {
  29. formattedInput += input[element];
  30. formattedInput += input[element];
  31. compressed.push_back(formattedInput);
  32. counter = 1;
  33. }
  34. else if (input[element] != input[element + 1] && counter > 2)
  35. {
  36. std::stringstream ss;
  37. ss << counter;
  38. formattedInput += ss.str();
  39. formattedInput += input[element];
  40. compressed.push_back(formattedInput);
  41. counter = 1;
  42. }
  43. }
  44.  
  45. for (auto i : compressed)
  46. {
  47. std::cout << i;
  48. }
  49. std::cout << std::endl;
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement