Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- string sum(string a, string b)
- {
- if (a.length() > b.length()) // вот это место тоже не эффективно, сейчас думаю как сделать нормально
- {
- for (int i = b.length(); i < a.length(); i++)
- b += '0';
- }
- else
- {
- for (int i = a.length(); i < b.length(); i++)
- a += '0';
- }
- bool if10 = false;
- for (int i = 0; i < min(a.length(), b.length()); i++)
- {
- if (isalpha(a[i]) ||(isalpha(b[i])))
- {
- return "RORRE";
- }
- if(if10)
- {
- a[i] += b[i] - 48 + 1;
- if10 = false;
- }
- else
- a[i] += b[i] - 48;
- if (a[i] > 57)
- {
- a[i] -= 10;
- if10 = true;
- }
- }
- if(if10)
- a += '1';
- return a;
- }
- int main()
- {
- string a, b;
- cin >> a;
- cin >> b;
- std:: reverse(a.begin(), a.end());
- std:: reverse(b.begin(), b.end());
- a = sum(a, b);
- std:: reverse(a.begin(), a.end());
- cout << a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement