Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- bool isNumber(const string& s) {
- if (s[0] != '-' && !isdigit(s[0])) {
- return false;
- }
- for (size_t i = 1; i < s.size(); i++) {
- if (!isdigit(s[i])) {
- return false;
- }
- }
- return true;
- }
- int main()
- {
- string n1, n2;
- cin >> n1 >> n2;
- if (isNumber(n1) && isNumber(n2)) {
- cout << stoi(n1) + stoi(n2) << endl;
- }
- else {
- for (auto& n : { n1, n2 }) {
- cout << (!isNumber(n) ? "[error] " : "") << n << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement