Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. vector <int> v;
  6.  
  7. int main()
  8. {
  9. int n;
  10. cin >> n;
  11. v = vector <int> (n + 1);
  12. for (int i = 1; i <= n; ++i)
  13. cin >> v[i];
  14.  
  15. int Lungime, LungimeMaxima = -1, BestStart = 0, BestStop = 0;
  16. for (int start = 1; start <= n; ++start)
  17. {
  18. for (int stop = start; stop <= n; ++stop)
  19. {
  20. if (v[start] == v[stop])
  21. {
  22. Lungime = stop - start + 1;
  23. if (Lungime > LungimeMaxima)
  24. {
  25. LungimeMaxima = Lungime;
  26. BestStart = start;
  27. BestStop = stop;
  28. }
  29. else
  30. {
  31. if (Lungime == LungimeMaxima)
  32. {
  33. BestStart = start;
  34. BestStop = stop;
  35. }
  36. }
  37. }
  38. }
  39. }
  40.  
  41. cout << BestStart << ' ' << BestStop;
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement