fork(4) download
  1. #include<iostream>
  2. #include<string>
  3. #include<unordered_set>
  4.  
  5. using namespace std;
  6.  
  7. string helper(string& s, int k) {
  8. if(s.size()<k) return s;
  9.  
  10. string str;
  11. for(int i=0; i<s.size(); i++){
  12. char currChar=s[i];
  13. int j=i+1, count=0;
  14. while(j<s.size() && count<=k && s[j]==currChar) {
  15. j++;
  16. count++;
  17. }
  18.  
  19. if(j-i==k) {
  20. for(int k=0; k<i; k++) str.push_back(s[k]);
  21. for(int k=j; k<s.size(); k++) str.push_back(s[k]);
  22. break;
  23. }
  24. }
  25.  
  26. if(str.empty()) return s;
  27. return helper(str, k);
  28. }
  29.  
  30. int main() {
  31. // string s="abbcccb";
  32. // string s="abcdef";
  33. // string s="baac";
  34. string s="aba";
  35. cout<<helper(s, 2);
  36. return 0;
  37. }
Success #stdin #stdout 0s 4320KB
stdin
Standard input is empty
stdout
aba