Advertisement
Spocoman

01. Gauss' Trick

Feb 8th, 2024
755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <memory>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     string line;
  10.     getline(cin, line);
  11.  
  12.     istringstream ss(line);
  13.  
  14.     unique_ptr<int[]> numbers = make_unique<int[]>(1000);
  15.  
  16.     int n, counter = 0;
  17.  
  18.     while (ss >> n) {
  19.         numbers[counter++] = n;
  20.     }
  21.  
  22.     for (int i = 0; i < counter / 2; i++) {
  23.         cout << numbers[i] + numbers[counter - (1 + i)] << ' ';
  24.     }
  25.  
  26.     if (counter % 2 == 1) {
  27.         cout << numbers[counter / 2];
  28.     }
  29.     cout << endl;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement