Advertisement
v4m4v4

OddEvenPosition1

Oct 12th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int number;
  8.     cin >> number;
  9.  
  10.     double even_sum = 0;
  11.     double odd_sum = 0;
  12.     double even_min = 1000000000.0;
  13.     double odd_min = 1000000000.0;
  14.     double even_max = -1000000000.0;
  15.     double odd_max = -1000000000.0;
  16.  
  17.     for (int i = 1; i <= number; i++)
  18.     {
  19.         double current_number;
  20.         cin >> current_number;
  21.  
  22.         if (i % 2 == 0)
  23.         {
  24.             even_sum += current_number;
  25.             if (current_number > even_max)
  26.             {
  27.                 even_max = current_number;
  28.             }
  29.             if (current_number < even_min)
  30.             {
  31.                 even_min = current_number;
  32.             }
  33.         }
  34.         else
  35.         {
  36.             odd_sum += current_number;
  37.             if (current_number > odd_max)
  38.             {
  39.                 odd_max = current_number;
  40.             }
  41.             if (current_number < odd_min)
  42.             {
  43.                 odd_min = current_number;
  44.             }
  45.         }
  46.     }
  47.     if (number > 1)
  48.     {
  49.         cout << "OddSum=" << odd_sum << "," << endl;
  50.         cout << "OddMin=" << odd_min << "," << endl;
  51.         cout << "OddMax=" << odd_max << "," << endl;
  52.         cout << "EvenSum=" << even_sum << "," << endl;
  53.         cout << "EvenMin=" << even_min << "," << endl;
  54.         cout << "EvenMax=" << even_max << endl;
  55.     }
  56.     if (number == 1)
  57.     {
  58.         cout << "OddSum=" << odd_sum << "," << endl;
  59.         cout << "OddMin=" << odd_min << "," << endl;
  60.         cout << "OddMax=" << odd_max << "," << endl;
  61.         cout << "EvenSum=" << 0 << "," << endl;
  62.         cout << "EvenMin=" << "No" << "," << endl;
  63.         cout << "EvenMax=" << "No" << endl;
  64.     }
  65.     if (number == 0)
  66.     {
  67.         cout << "OddSum=" << number << "," << endl;
  68.         cout << "OddMin=" << "No" << "," << endl;
  69.         cout << "OddMax=" << "No" << "," << endl;
  70.         cout << "EvenSum=" << number << "," << endl;
  71.         cout << "EvenMin=" << "No" << "," << endl;
  72.         cout << "EvenMax=" << "No" << endl;
  73.     }
  74.  
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement