Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main()
- {
- string s;
- getline(cin, s);
- vector<long long> a;
- for (long long i = 0; i < s.length(); ++i) {
- if (s[i] != ' ') {
- if (s[i] == '-') {
- i++;
- int t = 0;
- while (s[i] >= '0' && s[i] <= '9') {
- t = t*10 + s[i] - '0';
- i++;
- }
- a.push_back(-t);
- } else {
- int t = 0;
- while (s[i] >= '0' && s[i] <= '9') {
- t = t*10 + s[i] - '0';
- i++;
- }
- a.push_back(t);
- }
- }
- }
- /*for (int i = 0; i < a.size(); ++i) {
- cout << a[i] << " ";
- } cin.get();*/
- long long max1 = -10000000, min1 = 10000000;
- for (long long i = 0; i < a.size(); ++i) {
- if ( (i+1) % 2 == 0 ) {
- if (a[i] > max1) max1 = a[i];
- } else {
- if (a[i] < min1) min1 = a[i];
- }
- }
- cout << max1 + min1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment