Codeforces Comparing Two Long Integers

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

int main()
{
    ios_base::sync_with_stdio(false);

    string a,b;

    while(cin >> a >> b)
    {
//        if(a > b) cout << ">\n";
//        else if(a < b) cout << "<\n";
//        else if(a == b) cout << "=\n";
        //cout << a.length() << " " << b.length() << "\n";

            string tmp="";

            LL dif=0 , i=0;

            bool a_boro=false, b_boro=false;

            if(a.length() > b.length())
            {
                dif = a.length() - b.length();
                a_boro = true;
            }

            else if(a.length() < b.length())
            {
                dif = b.length() - a.length();
                b_boro=true;
            }

            if(a_boro)
            {
                tmp="";

                for(i=0; i<dif; i++)
                {
                    tmp+="0";
                }

                b = tmp + b;
            }

            if(b_boro)
            {
                tmp="";

                for(i=0; i<dif; i++)
                {
                    tmp+="0";
                }

                a = tmp + a;
            }

            if(a > b) cout << ">\n";
            else if(a < b) cout << "<\n";
            else cout << "=\n";
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number