UVA10473 Simple Base Conversion【进制转换】
2018-01-20 21:00
639 查看
In this problem you are asked to write a simplebase conversion program. You will be givena hexadecimal or decimal integer number as input.You will have to output the correspondingdecimal or hexadecimal number. Hexadecimalnumbers always starts with a ‘0x’
and all othernumbers are to be considered as decimal numbers.There will be no invalid numbers in theinput.
Input
The input file contains several lines of input. Each line contains a single non-negative number, whichmay be a decimal or hexadecimal number as explained in the problem statement. The decimal value ofthis number will be less than 231. A line containing a
negative decimal number terminates input. Thisnumber should not be processed. Input numbers will contain no space within them.
Output
For each line of input (Except the last one) produce one line of output. This line should contain thedecimal or hexadecimal representation of the corresponding hexadecimal or decimal number. Like theinput, the hexadecimal numbers in the output should be
preceded by a ‘0x’.
Sample Input
4
7
44
0x80685
-1
Sample Output
0x4
0x7
0x2C
525957
问题链接:UVA10473 Simple Base Conversion
问题简述:(略)
问题分析:
这是一个进制转换问题,要充分利用格式化输入输出函数和字符串与整数之间转换的函数。
充分利用这些函数,程序逻辑就简单了。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C语言程序如下:
/* UVA10473 Simple Base Conversion */
#include <stdio.h>
#include <stdlib.h>
#define N 16
char s
;
int main(void)
{
while (gets(s) != NULL && s[0] != '-')
if(s[1] == 'x')
printf("%ld\n", strtol(s, NULL, 16));
else
printf("0x%X\n", atoi(s));
return 0;
}
and all othernumbers are to be considered as decimal numbers.There will be no invalid numbers in theinput.
Input
The input file contains several lines of input. Each line contains a single non-negative number, whichmay be a decimal or hexadecimal number as explained in the problem statement. The decimal value ofthis number will be less than 231. A line containing a
negative decimal number terminates input. Thisnumber should not be processed. Input numbers will contain no space within them.
Output
For each line of input (Except the last one) produce one line of output. This line should contain thedecimal or hexadecimal representation of the corresponding hexadecimal or decimal number. Like theinput, the hexadecimal numbers in the output should be
preceded by a ‘0x’.
Sample Input
4
7
44
0x80685
-1
Sample Output
0x4
0x7
0x2C
525957
问题链接:UVA10473 Simple Base Conversion
问题简述:(略)
问题分析:
这是一个进制转换问题,要充分利用格式化输入输出函数和字符串与整数之间转换的函数。
充分利用这些函数,程序逻辑就简单了。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C语言程序如下:
/* UVA10473 Simple Base Conversion */
#include <stdio.h>
#include <stdlib.h>
#define N 16
char s
;
int main(void)
{
while (gets(s) != NULL && s[0] != '-')
if(s[1] == 'x')
printf("%ld\n", strtol(s, NULL, 16));
else
printf("0x%X\n", atoi(s));
return 0;
}
相关文章推荐
- UVa 10473 Simple Base Conversion (两句话实现进制转换)
- UVa 10473 - Simple Base Conversion
- UVa 10473 - Simple Base Conversion
- NUMBER BASE CONVERSION(大数进制转换)
- 高精度进制转换 poj 1220 NUMBER BASE CONVERSION
- POJ 1220 NUMBER BASE CONVERSION(高精度--进制转换)
- error C2663: 'ATL::CSimpleStringT<BaseType>::GetBuffer' : 2 overloads have no legal conversion for
- POJ 1220 NUMBER BASE CONVERSION(较复杂的进制转换)
- 进制转换小结(大数的任意进制转换)spoj429 Simple Numbers Conversion,poj 1220NUMBER BASE CONVERSION
- UVA 11121 Base -2 (进制转换)
- Simple base conversion implementation use java
- NUMBER BASE CONVERSION(进制转换)
- POJ 1220 NUMBER BASE CONVERSION(高精度进制转换)
- poj 1220 NUMBER BASE CONVERSION 高精度进制转换
- pku 1220--NUMBER BASE CONVERSION(高精度进制转换)
- 进制转换 poj1220-NUMBER BASE CONVERSION
- UVa 11121 Base -2 / 进制转换
- Android简便通用的SimpleBaseAdapter
- SimpleAdapter和ArrayAdapter和BaseAdapter的适用场景
- A simple webframe base on web.py