ACM (UVa) : 10473


#include <iostream>
#include <cctype>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main ()
{
	long n;
	char a [20];
	a [1] = ' ';

	while ( gets (a) ) {

		if ( a [0] == '0' && a [1] == 'x' ) {
			n = strtol (a, NULL, 16);
			printf ("%ld\n",n);
		}

		else {
			n = atoi (a);
			if ( n < 0 )
				return 0;
			printf("0x%X\n", atoi ( a ));
		}
		a [1] = ' ';
	}

	return 0;
}

Advertisements

3 thoughts on “ACM (UVa) : 10473

  1. I got a n better idea to solve this problem from this code than that i have ever. But this code is not a acceptable code.

  2. @salma jahan,
    would you tell me why this is not an acceptable code?

    // ——-
    ya, my bad, there was a compilation error. i have just fixed it. thanks 🙂

  3. sorry, i was unconscious. the simple mistake was ‘ you don’t include for a[1]==X capital x.
    however pfrom you i learnt many thing. thanx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s