Cod sursa(job #1181926)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 4 mai 2014 12:02:42
Problema A+B Scor 100
Compilator cpp Status done
Runda Lista lui wefgef Marime 1.01 kb
#include <iostream>
#include <fstream>

using namespace std;

inline bool BIT( int n, int i )
{
    return ( n & ( 1 << i ) );
}

int main()
{
    ifstream f("adunare.in");
    ofstream g("adunare.out");

    int a, b, c = 0, tr = 0;

    f >> a >> b;

    for ( int i = 0; i < 31; ++i )
    {
        int s = BIT( a, i ) + BIT( b, i ) + tr;

        if ( s == 0 ) continue;

        if ( s <= 1 )
        {
            c |= ( 1 << i );
            tr = 0;
        }
        else
        {
            if ( s % 2 == 0 )
            {
                tr = 1;
            }
            else
            {
                if ( s == 1 )
                {
                    c |= ( 1 << i );
                    tr = 0;
                }
                else
                {
                    c |= ( 1 << i );
                    tr = 1;
                }
            }
        }
    }

    if ( tr )
    {
        c |= ( 1 << 31 );
    }

    g << c;

    return 0;
}