Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4. #include<sstream>
  5.  
  6. int com(int cut_num, std::string str) {
  7. std::vector<std::string> v;
  8. std::string prev_str;
  9. std::stringstream result_str;
  10. int j = 0,cnt=0;
  11. for (int i = 0; i < str.size(); i+=cut_num) {
  12. v.push_back(str.substr(i,cut_num));
  13. }
  14. prev_str = v[0];
  15. for (int i = 0; i < v.size(); i++) {
  16. if (prev_str != v[i]) {
  17. result_str << prev_str;
  18. if (cnt != 1) {
  19. result_str << cnt;
  20. }
  21. prev_str = v[i];
  22. cnt = 1;
  23. }
  24. else {
  25. cnt++;
  26. }
  27. }
  28. if (cnt != 1) {
  29. result_str << prev_str << cnt;
  30. }
  31. else {
  32. result_str << prev_str;
  33. }
  34. return result_str.tellp();
  35. }
  36.  
  37. int main() {
  38. std::string str;
  39. std::cin >> str;
  40. int min = 0,num;
  41. min = com(1, str);
  42. for(int i = 2 ; i < str.size() ; i++){
  43. num = com(i, str);
  44. if (min > num) {
  45. min = num;
  46. }
  47. }
  48. printf("%d", min);
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement