IISergeyII

Untitled

May 27th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <algorithm>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12.     string s;
  13.     getline(cin, s);
  14.  
  15.     vector<long long> a;
  16.  
  17.     for (long long i = 0; i < s.length(); ++i) {
  18.         if (s[i] != ' ') {
  19.             if (s[i] == '-') {
  20.                 i++;
  21.                 int t = 0;
  22.  
  23.                 while (s[i] >= '0' && s[i] <= '9')  {
  24.                     t = t*10 + s[i] - '0';
  25.                     i++;
  26.                 }
  27.                 a.push_back(-t);
  28.  
  29.             } else {
  30.                 int t = 0;
  31.  
  32.                 while (s[i] >= '0' && s[i] <= '9')  {
  33.                     t = t*10 + s[i] - '0';
  34.                     i++;
  35.                 }
  36.                 a.push_back(t);
  37.             }
  38.         }
  39.     }
  40.  
  41.     /*for (int i = 0; i < a.size(); ++i) {
  42.         cout << a[i] << " ";
  43.     } cin.get();*/
  44.  
  45.     long long max1 = -10000000, min1 = 10000000;
  46.     for (long long i = 0; i < a.size(); ++i) {
  47.         if ( (i+1) % 2 == 0 ) {
  48.             if (a[i] > max1) max1 = a[i];
  49.         } else {
  50.             if (a[i] < min1) min1 = a[i];
  51.         }
  52.     }
  53.     cout << max1 + min1;
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment