fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7. using std::string;
  8. using std::vector;
  9.  
  10. int main(int argc, const char * argv[])
  11. {
  12.  
  13. vector<int> ivec;
  14. int input;
  15. while (cin >> input)
  16. {
  17. ivec.push_back(input);
  18. }
  19.  
  20. if (ivec.size() % 2 == 0) // if even # of elements
  21. {
  22. for (vector<int>::size_type index = 0; index < ivec.size()/2; ++index)
  23. {
  24. cout << ivec[index] << "+" << (ivec.size()-index) << endl;
  25. }
  26. }
  27. else // if odd # of elements
  28. {
  29. cout << "---\n" << "Odd # of elements\nLast value is: " << ivec.size()-1 << endl;
  30. }
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
Standard output is empty