Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     setlocale(0, "");
  8.  
  9.     const int n = 117;
  10.  
  11.     int p1 = 0, p2 = 0, y = 0, max = 0, q1 = 0, q2 = 0;
  12.  
  13.     int arr[n] = {};
  14.  
  15.     cout << "Введите числа подряд: ";
  16.     cin >> y;
  17.     cin >> q1;
  18.  
  19.     for (int i = 0; i < n; i++)
  20.         arr[i] = 0;
  21.  
  22.     for (int i = 2; i <= y; i++)
  23.     {
  24.         cin >> q2;
  25.  
  26.         if (q1 > arr[q1 % n])
  27.             arr[q1 % n] = q1;
  28.  
  29.         for (int j = 0; j < n; j++)
  30.         {
  31.             if ((arr[j] + q2 > max) && ((arr[j] + q2) % n == 0) && (arr[j] > q2))
  32.             {
  33.                 max = arr[j] + q2;
  34.                 p1 = arr[j];
  35.                 p2 = q2;
  36.             }
  37.         }
  38.  
  39.         q1 = q2;
  40.     }
  41.  
  42.     if ((p1 + p2) > 0)
  43.         cout << p1 << ' ' << p2;
  44.     else
  45.         cout << "NO";
  46.  
  47.     cout << endl << endl;
  48.  
  49.     system("pause");
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement