POJ 1331 Mutiply strtol()进制转换函数
来源:互联网 发布:淘宝直播右下角的心 编辑:程序博客网 时间:2024/05/17 08:47
http://poj.org/problem?id=1331
Description
You are to write a program which inputs three integers p, q, and r and determines the base B (2<=B<=16) for which p * q = r. If there are many candidates for B, output the smallest one. For example, let p = 11, q = 11, and r = 121. Then we have 11(3) * 11(3) = 121(3) because 11(3) = 1 * 31 + 1 * 30 = 4(10) and 121(3) = 1 * 32 + 2 * 31 + 1 * 30 = 16(10). For another base such as 10, we also have 11(10) * 11(10) = 121(10). In this case, your program should output 3 which is the smallest base. If there is no candidate for B, output 0.
Input
Output
Sample Input
36 9 4211 11 1212 2 2
Sample Output
1330
函数声明
函数及其参数
long int strtol(const char *nptr,char **endptr,int base);
函数的解释说明:
这个函数会将参数nptr字符串根据参数base来转换成长整型数。参数base范围从2至36,或0。参数base代表采用的进制方式,如base值为10则采用10进制,若base值为16则采用16进制等。当base值为0时则是采用10进制做转换,但遇到如’0x’前置字符则会使用16进制做转换、遇到’0’前置字符而不是’0x’的时候会使用8进制做转换。一开始strtol()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,再遇到非数字或字符串结束时('/0')结束转换,并将结果返回。若参数endptr不为NULL,则会将遇到不合条件而终止的nptr中的字符指针由endptr返回。
strtol是atoi的增强版,主要体现在这几方面:
1.不仅可以识别十进制整数,还可以识别其它进制的整数,取决于base参数,比如strtol("0XDEADbeE~~", NULL, 16)返回0xdeadbee的值,strtol("0777~~", NULL, 8)返回0777的值。
2.endptr是一个传出参数,函数返回时指向后面未被识别的第一个字符。例如char *pos; strtol("123abc", &pos, 10);,strtol返回123,pos指向字符串中的字母a。如果字符串开头没有可识别的整数,例如char *pos; strtol("ABCabc", &pos, 10);,则strtol返回0,pos指向字符串开头,可以据此判断这种出错的情况,而这是atoi处理不了的。
3.如果字符串中的整数值超出long int的表示范围(上溢或下溢),则strtol返回它所能表示的最大(或最小)整数,并设置errno为ERANGE,例如strtol("0XDEADbeef~~", NULL, 16)返回0x7fffffff并设置errno为ERANGE
- POJ 1331 Mutiply strtol()进制转换函数
- strtol函数---将字符串按一定的进制转换
- 强大的进制转换strtol
- strtol函数 将字符串转换为相应进制的整数
- strtol函数 将字符串转换为相应进制的整数
- atoi,itoi,atol,strtol, strtod函数转换
- atoi,atol,strtol等几个转换函数
- strtol字符串转换函数应用实例
- strtol----将16进制字符串转换为整数
- strtol() 函数
- strtol函数
- strtol()函数
- strtol函数
- strtol 函数
- strtol函数
- strtol函数
- strtol函数
- strtol函数
- Android基础(二) LinearLayout
- 统计服务器响应时间的利器
- 两个DataTable连接实例
- .Net winform拖动工作区移动窗体
- D3DPT一系列枚举值的含义
- POJ 1331 Mutiply strtol()进制转换函数
- C++中的零散重要知识点
- 从【各大软件公司笔试压轴题】学习SQL语句
- Zenoss
- Secure Software Installation on Smartphones 笔记
- 11年上班的第一天,老板要我换部门或是换公司。
- java.net.URL例子
- JAVA之——GC
- 一个简单的arm开发板的制作过程