Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- using namespace std;
- int main() {
- string line;
- // Read input line by line
- while (getline(cin, line)) {
- istringstream iss(line);
- int a, b;
- if (iss >> a) {
- if (iss >> b) {
- // Case: two numbers on the line
- cout << (a + b) << endl;
- } else {
- // Case: only one number on the line, sum its digits
- int sum = 0;
- while (a != 0) {
- sum += a % 10;
- a /= 10;
- }
- cout << sum << endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement