daily pastebin goal
4%
SHARE
TWEET

OddEvenPosition

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