Editorial for Ресто


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by: maya

Тестовете можете да видите тук.

Примерни решения на C++:

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

int main()
{
    string a, c="",b;
    cin>>a>>b;

    if (a==b) cout<<0<<endl;
    else
    {
        string d(a.size()-b.size(),'0');
        b=d+b;
        for (int i=a.size()-1; i>=0; i--)
            if (a[i]>=b[i]) c=char(a[i]-b[i]+48)+c;
            else
            {
                c=char(10+a[i]-b[i]+48)+c;
                int s=i-1;
                while (a[s]=='0')
                {
                    a[s]='9';
                    s--;
                }
                a[s]--;
            }
        while (c[0]=='0') c.erase(0,1);
        cout<<c<<endl;
    }
    return 0;
}

Comments

There are no comments at the moment.