Click Here to go back to the homepage.

Yoda Solution:


#include <bits/stdc++.h>
using namespace std;
//right aligned
int main() {
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    string str1, str2;
    cin >> str1 >> str2;
    string res1, res2;
    auto it1 = str1.rbegin(), it2=str2.rbegin();
    while(it1 != str1.rend() || it2 != str2.rend()){
        char c1 = it1 == str1.rend() ? '0' : *it1;
        char c2 = it2 == str2.rend() ? '0' : *it2;
        if(c1 == c2){
            res1.insert(0, 1, c1);
            res2.insert(0, 1, c2);
        } else if(c1 < c2){
            res2.insert(0, 1, c2);
        } else {
            res1.insert(0, 1, c1);
        }
        it1 = it1 == str1.rend() ? str1.rend() : next(it1);
        it2 = it2 == str2.rend() ? str2.rend() : next(it2);
    }
    cout << (res1.length() > 0 ? to_string(stoi(res1)) : "YODA") << endl;
    cout << (res2.length() > 0 ? to_string(stoi(res2)) : "YODA") << endl;

    return 0;
}