fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string s="Dog goes woof\nCat goes meow\nBird goes tweet\nand mouse goes squeek\nCow goes moo\nFrog goes croak\nand the elephant goes toot\nDucks say quack\nand fish go blub\nand the seal goes ow ow ow";
  7. cout<<"Вхідний текст: "<<endl<<s<<endl;
  8.  
  9. string And="and";
  10. size_t pos=s.find(And);
  11. while(pos!=string::npos){
  12. s.erase(pos,And.length());
  13. pos=s.find(And);
  14. }
  15. string change[]={" goes "," say "," go "};
  16. string changer=" - ";
  17. for(size_t i=0;i<3;++i){
  18. string past=change[i];
  19. pos=s.find(past);
  20. while(pos!=string::npos){
  21. s.replace(pos,past.length(),changer);
  22. pos=s.find(past,pos+changer.length());
  23. }
  24. }
  25. cout<<"Результат: "<<endl<<s;
  26. return 0;
  27. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Вхідний текст: 
Dog goes woof
Cat goes meow
Bird goes tweet
and mouse goes squeek
Cow goes moo
Frog goes croak
and the elephant goes toot
Ducks say quack
and fish go blub
and the seal goes ow ow ow
Результат: 
Dog - woof
Cat - meow
Bird - tweet
 mouse - squeek
Cow - moo
Frog - croak
 the elephant - toot
Ducks - quack
 fish - blub
 the seal - ow ow ow