fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #define SIZE 1001
  4. using namespace std;
  5.  
  6. int countWords(char* speech)
  7. {
  8. int wordCount = 0;
  9. char delim[] = " ,.!?:;-\"\'";
  10. char* pointer = strtok(speech, delim);
  11. while (pointer != NULL)
  12. {
  13. pointer = strtok(NULL, delim);
  14. wordCount++;
  15. }
  16. return wordCount;
  17. }
  18.  
  19. int countSyllables(char* speech)
  20. {
  21. int syllableCount = 0;
  22. char vowels[] = "aoeuAOEU";
  23. char* pointer = strpbrk(speech, vowels);
  24. while (pointer != NULL)
  25. {
  26. pointer = strpbrk(pointer + 1, vowels);
  27. syllableCount++;
  28. }
  29. return syllableCount;
  30. }
  31.  
  32. int main()
  33. {
  34. int n;
  35. cin >> n;
  36. char speech[SIZE];
  37. int words[n];
  38. int syllables[n];
  39. cin.ignore();
  40. for (int i = 0; i < n; i++)
  41. {
  42. cin.getline(speech, SIZE);
  43. syllables[i] = countSyllables(speech);
  44. words[i] = countWords(speech);
  45. }
  46. bool many = false;
  47. int winner = 0;
  48. for (int i = 1; i < n; i++)
  49. {
  50. if (syllables[i] * words[winner] < syllables[winner] * words[i])
  51. {
  52. winner = i;
  53. many = false;
  54. }
  55. else if (syllables[i] * words[winner] == syllables[winner] * words[i])
  56. {
  57. if (words[winner] < words[i])
  58. {
  59. winner = i;
  60. many = false;
  61. }
  62. else if (words[winner] == words[i])
  63. many = true;
  64. }
  65. }
  66. if (many)
  67. cout << "O-o-o-rks...";
  68. else
  69. cout << winner + 1 << endl;
  70. return 0;
  71. }
Success #stdin #stdout 0s 3464KB
stdin
5
Winter is coming...
A Lannister always pays his debts.
Hear me roar!
King of the North!
Sherlock?
stdout
1