Untitled
unknown
c_cpp
a year ago
1.1 kB
3
Indexable
Never
#include <iostream> using namespace std; int main() { int a, b, res; cin >> a >> b; int lenA = 0, lenB = 0, temp = a; while (temp > 0) { lenA++; temp /= 10; } temp = b; while (temp > 0) { lenB++; temp /= 10; } if (lenA == lenB) { res = a; for (int i = 0; i < lenA; i++) { res *= 10; } res += b; } else { if (lenA < lenB) { temp = a; a = b; b = temp; temp = lenA; lenA = lenB; lenB = temp; } res = b; for(int i = 0; i < (lenA - lenB); i++) { res *= 10; } for (int i = 0; i < (lenA - lenB); i++) { int powerOf10 = 1; for (int j = 0; j < i; j++) { powerOf10 *= 10; } res += (a % 10) * powerOf10; a /= 10; } } cout << res; }