UVa 10473 Simple Base Conversion (两句话实现进制转换)

10473 - Simple Base Conversion

Time limit: 3.000 seconds 

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1414


10->16:atoi+%X

16->10:strtol+%d


完整代码:

/*0.019s*/

#include<cstdio>
#include<cstdlib>

char s[15];

int main()
{
	while (gets(s), s[0] != '-')
		if (s[1] == 'x') printf("%d\n", strtol(s, NULL, 16));
		else printf("0x%X\n", atoi(s));///注意十六进制中的字母要大写
	return 0;
}

你可能感兴趣的:(C++,ACM,uva)