Advertisement
Guest User

Untitled

a guest
Mar 26th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. bool flag = false;
  8. int array[100];
  9. int length1, i, maxSequence = INT_MIN, sequence = 1, mostUsedNum = 0;
  10. cin >> length1;
  11. for (i = 0; i < length1; i++)
  12. {
  13. cin >> array[i];
  14. }
  15. for (i = 0; i < length1; i++)
  16. {
  17. if (array[i] != array[i + 1])
  18. {
  19. sequence = 1;
  20. }
  21. else
  22. {
  23. sequence++;
  24. flag = true;
  25. }
  26. if (sequence > maxSequence)
  27. {
  28. maxSequence = sequence;
  29. mostUsedNum = array[i];
  30. }
  31. }
  32. if (flag == false)
  33. {
  34. cout << array[length1 - 1];
  35. }
  36. else
  37. {
  38. while (maxSequence > 0)
  39. {
  40. cout << mostUsedNum << " ";
  41. maxSequence--;
  42. }
  43. }
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement