fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string s="Dog - woof\n"
  7. "Cat - meow\n"
  8. "Bird - tweet\n"
  9. "mouse - squeek\n"
  10. "Cow - moo\n"
  11. "Frog - croak\n"
  12. "the elephant - toot\n"
  13. "Ducks - quack\n"
  14. "fish - blub\n"
  15. "the seal - ow ow ow";
  16. string line;
  17. size_t start=0;
  18. while(true){
  19. size_t end=s.find('\n',start);
  20. if(end==string::npos)line=s.substr(start);
  21. else line=s.substr(start,end-start);
  22. size_t pos=line.find("-");
  23. if(pos!=string::npos){
  24. string animal=line.substr(0,pos);
  25. while(!animal.empty()&&animal.front()==' ')animal.erase(0,1);
  26. bool b=true ;
  27. for(size_t i=0;i<animal.size();++i){
  28. if(animal[i]==' ')b=true;
  29. else if(b){
  30. if(animal[i]>='a'&&animal[i]<='z')animal[i]-=32;
  31. b=false;
  32.  
  33. }
  34. }
  35. cout<<animal;
  36. }
  37. if(end==string::npos)break;
  38. start=end+1;
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Dog Cat Bird Mouse Cow Frog The Elephant Ducks Fish The Seal