Advertisement
Spocoman

05. Multiply Evens Sum by Odds

Oct 27th, 2023
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string n;
  7.     cin >> n;
  8.  
  9.     int evenSum = 0;
  10.     int oddSum = 0;
  11.  
  12.     for (int i = 0; i < n.length(); i++) {
  13.         if (n[i] != '-') {
  14.             (n[i] % 2 == 0 ? evenSum : oddSum) += n[i] - 48;
  15.         }
  16.     }
  17.  
  18.     cout << evenSum * oddSum << endl;
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement