Saturday, March 16, 2013

UVa 10473 - Simple Base Conversion

Accepted date: 2012-08-05
Ranking (as of 2013-03-16): 265
Language: C++

/*
  UVa 10473 - Simple Base Conversion

  To build using Visucal Studio 2008:
    cl -EHsc -O2 simple_base_conversion.cpp
*/

#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
  while (true) {
    char number[16];
    scanf("%s", number);
    if (number[0] == '0' && number[1] == 'x')
      printf("%d\n", strtol(number, NULL, 16));
    else {
      int n = strtol(number, NULL, 10);
      if (n < 0)
        break;
      else
        printf("0x%X\n", n);
    }
  }
  return 0;
}

No comments:

Post a Comment