fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_WORDS = 100;
  6. const int MAX_LETTERS = 20;
  7.  
  8. int findFrequestLength(int totalWords[]) {
  9. int maxWords = 0, frequestLength = 0;
  10. for (int i = MAX_LETTERS; i > 0; --i) {
  11. if (totalWords[i] > maxWords) {
  12. maxWords = totalWords[i];
  13. frequestLength = i;
  14. }
  15. }
  16. return frequestLength;
  17. }
  18.  
  19. int main() {
  20. int n, totalWords[MAX_LETTERS + 1] = {0};
  21. char words[MAX_WORDS][MAX_LETTERS + 1] = {0};
  22. cin >> n;
  23. for (int i = 0; i < n; ++i) {
  24. cin >> words[i];
  25. ++totalWords[strlen(words[i])];
  26. }
  27. int frequestLength = findFrequestLength(totalWords);
  28. for (int i = 0; i < n; ++i) {
  29. if (strlen(words[i]) == frequestLength) {
  30. cout << words[i] << ' ';
  31. }
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5288KB
stdin
4
Apple
Apple
Abcdefgij
Apple
stdout
Apple Apple Apple