fork download
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main()
  9. {
  10. char s[255];
  11. cin.get(s, 255);
  12. cin.get();
  13. int vowel_count=0, word_count=0;
  14. const char separators[]=" \t?.,;:";
  15. const char vowels[]="aeiouyAEIOUY";
  16. bool new_word=true;
  17. char *p=s;
  18. cout << "Vowels in each word: ";
  19. do {
  20. if (*p=='\0' || strchr(separators,*p)) {
  21. if (!new_word) { // here, we've reached the end of a word
  22. word_count++;
  23. cout << vowel_count << " ";
  24. vowel_count = 0;
  25. new_word=true;
  26. } // else it's still a new word since consecutive separators
  27. }
  28. else {
  29. new_word=false; // we have at least on char in our word
  30. if (strchr(vowels, *p))
  31. vowel_count++;
  32. }
  33. } while (*p++);
  34. cout << endl<<"Words: "<<word_count<<endl;
  35. return 0;
  36. }
Success #stdin #stdout 0s 15232KB
stdin
aaaru xxx uutu,,uip 
stdout
Vowels in each word: 4 0 3 2 
Words: 4