Converting Numbers
Completed
Read two words that contain integers. Convert them with stoi, add them, and print the sum and the number of digits in the sum (via to_string).
Input
Two integers as words.
Output
Two lines.
Example
Input
120 34
Output
154 3
Editor
C++
Hints
stoi turns a string into an int; to_string goes the other way.
Solution explanation
Converting to a string is an easy way to count digits.
Show solution
#include <iostream>
#include <string>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int sum = stoi(a) + stoi(b);
string digits = to_string(sum);
if (digits[0] == '-') digits = digits.substr(1);
cout << sum << "\n" << digits.size() << "\n";
return 0;
}