Advertisement
Spocoman

5. Print Even Numbers

Jan 10th, 2024
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <queue>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     string line;
  10.     getline(cin, line);
  11.  
  12.     istringstream ss(line);
  13.  
  14.     queue<int> numbers;
  15.  
  16.     int number;
  17.  
  18.     while (ss >> number) {
  19.         if (number % 2 == 0) {
  20.             numbers.push(number);
  21.         }
  22.     }
  23.  
  24.     while (!numbers.empty()) {
  25.         if (numbers.size() == 1) {
  26.             cout << numbers.front() << endl;
  27.         }
  28.         else {
  29.             cout << numbers.front() << ", ";
  30.         }
  31.         numbers.pop();    
  32.     }
  33.    
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement