fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 2000;
  6.  
  7. short cntVowelsWord(const string &word) {
  8. short cntVowels = 0;
  9. const string vowels = "AEIOUaeiou";
  10. for (char letter : word) {
  11. if (vowels.find(letter) != string::npos) {
  12. ++cntVowels;
  13. }
  14. }
  15. return cntVowels;
  16. }
  17.  
  18. bool hasValidWord(const string &word) {
  19. return (int)word.size() == 6 && cntVowelsWord(word) <= 3;
  20. }
  21.  
  22. void splitWords(const string &text, string *validWords, int &noValidWords) {
  23. string currWord;
  24. const int lenText = (int)text.size();
  25. for (int i = 0; i <= lenText; ++i) {
  26. if (isalpha(text[i])) {
  27. currWord += text[i];
  28. } else if (!currWord.empty()) {
  29. if (hasValidWord(currWord)) {
  30. validWords[noValidWords++] += currWord;
  31. }
  32. currWord.clear();
  33. }
  34. }
  35. }
  36.  
  37. void sortLex(string *validWords, const int &noValidWords) {
  38. for (int i = 0; i < noValidWords - 1; ++i) {
  39. for (int j = i + 1; j < noValidWords; ++j) {
  40. if (validWords[i] > validWords[j]) {
  41. swap(validWords[i], validWords[j]);
  42. }
  43. }
  44. }
  45. }
  46.  
  47. void printWords(const string *validWords, const int &noValidWords) {
  48. for (int i = 0; i < noValidWords; ++i) {
  49. cout << validWords[i] << '\n';
  50. }
  51. }
  52.  
  53. int main() {
  54. string validWords[MAX_SIZE], text;
  55. int noValidWords = 0;
  56. while (getline(cin, text)) {
  57. splitWords(text, validWords, noValidWords);
  58. }
  59. sortLex(validWords, noValidWords);
  60. printWords(validWords, noValidWords);
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0.01s 5264KB
stdin
safk.as.fa.
1213
stdout
Standard output is empty