fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 10000;
  5. const int MAX_VALUE = 500;
  6.  
  7. int main() {
  8. int noElements, v[MAX_SIZE + 1], frq[MAX_VALUE + 1] = {
  9. 0
  10. };
  11. cin >> noElements;
  12. for (int i = 1; i <= noElements; ++i) {
  13. cin >> v[i];
  14. ++frq[v[i]];
  15. }
  16. int mostFrElement = 0;
  17. int maxFrequency = 0;
  18. for (int i = 0; i <= MAX_VALUE; ++i) {
  19. if (frq[i] > maxFrequency) {
  20. maxFrequency = frq[i];
  21. mostFrElement = i;
  22. } else if (frq[i] == maxFrequency) {
  23. if (i > mostFrElement) {
  24. mostFrElement = i;
  25. }
  26. }
  27. }
  28. cout << mostFrElement; // Afișăm elementul cu cea mai mare frecvență,sau care este cel mai mare de pe frecventa cea mai mare
  29. return 0;
  30. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
500