All pastes #451486 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-04-21 15:52 UTC
rendered paste body
#include <stdio.h>


int getnumber(){
        char c;

        int hex=0;
        int sign=0;
        int sum=0;
        int pos=0;
        while ( ( c=getchar() ) != '\n' )
        {
                if(pos==0&&c=='0')hex=1;
                if(pos==1&&c=='x')if(hex==1)hex=2;
                if( c >= '0' && c <='9' )
                        sum = hex==2?16*sum + (c - '0'):10*sum+(c-'0');

                else if(hex==2&&c>='a'&&c<='f')
                        sum=16*sum+(c-'a');
                        if( pos==0 && c == '-' )
                                sign = 1;
                pos++;
        }

        if ( sign )
                return -1 * sum;

        return sum;
}


main(){

        printf("%d", getnumber());
        return 0;
}