fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. std::string s("sfsfsgsdshhdfjj");
  7.  
  8. string str;
  9. str.resize(s.length() * 3/2);
  10. size_t size = 0;
  11.  
  12. for (size_t i = 0; i < s.length(); ++i) {
  13. str[size++] = s[i++];
  14. if (i < s.length()) {
  15. str[size++] = s[i];
  16. if (i != s.length() - 1)
  17. str[size++] = '-';
  18. }
  19. }
  20. // ;-)
  21. str.resize(size);
  22.  
  23. cout << str << endl;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
sf-sf-sg-sd-sh-hd-fj-j