fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 2000;
  6. const int TOTAL_WORDS = 285;
  7. const int TOTAL_LETTERS = 6;
  8.  
  9. void interchangeWords(char firstWord[], char secondWord[]) {
  10. char aux[TOTAL_LETTERS + 1] = {0};
  11. strcpy(aux, firstWord);
  12. strcpy(firstWord, secondWord);
  13. strcpy(secondWord, aux);
  14. }
  15.  
  16. void sortLyrics(char lyrics[][TOTAL_LETTERS + 1]) {
  17. for (int i = 0; lyrics[i]; ++i) {
  18. for (int j = i + 1; lyrics[j]; ++j) {
  19. if (strcmp(lyrics[i], lyrics[j]) > 0) {
  20. interchangeWords(lyrics[i], lyrics[j]);
  21. }
  22. }
  23. }
  24. }
  25.  
  26. bool isLetter(char c) {
  27. return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
  28. }
  29.  
  30. bool isVowel(char c) {
  31. const int CASE_DIFFERENCE = 'a' - 'A';
  32. const char allLowerVowels[] = "aeiou";
  33. for (int i = 0; allLowerVowels[i]; ++i) {
  34. if (c == allLowerVowels[i] || c == allLowerVowels[i] - CASE_DIFFERENCE) {
  35. return true;
  36. }
  37. }
  38. return false;
  39. }
  40.  
  41. int totalVowels(const char currentWord[]) {
  42. int numVowels = 0;
  43. for (int i = 0; currentWord[i]; ++i) {
  44. if (isVowel(currentWord[i])) {
  45. ++numVowels;
  46. }
  47. }
  48. return numVowels;
  49. }
  50.  
  51. bool requiredLyric(const char currentWord[]) {
  52. return strlen(currentWord) == TOTAL_LETTERS && totalVowels(currentWord) > 2;
  53. }
  54.  
  55. void storeLyrics(char lyrics[][TOTAL_LETTERS + 1], int &totalLyrics, const char text[]) {
  56. char currentWord[MAX_SIZE + 1] = {0};
  57. bool wasLetter = false;
  58. int lenghtText = strlen(text);
  59. for (int i = 0; i <= lenghtText; ++i) {
  60. if (isLetter(text[i])) {
  61. char currentLetter[] = {text[i], 0};
  62. strcat(currentWord, currentLetter);
  63. wasLetter = true;
  64. } else if (wasLetter) {
  65. if (requiredLyric(currentWord)) {
  66. strcpy(lyrics[totalLyrics], currentWord);
  67. ++totalLyrics;
  68. }
  69. currentWord[0] = 0;
  70. wasLetter = false;
  71. }
  72. }
  73. }
  74.  
  75. int main() {
  76. char text[MAX_SIZE + 1], lyrics[TOTAL_WORDS][TOTAL_LETTERS + 1];
  77. int totalLyrics = 0;
  78. while (cin.getline(text, MAX_SIZE + 1)) {
  79. storeLyrics(lyrics, totalLyrics, text);
  80. }
  81. sortLyrics(lyrics);
  82. for (int i = 0; lyrics[i][0]; ++i) {
  83. cout << lyrics[i] << '\n';
  84. }
  85. return 0;
  86. }
Success #stdin #stdout 0.01s 5288KB
stdin
a.e.i.o.u.aeeio
Abcdeiruo
stdout
Standard output is empty