POJ 2105 IP Address

http://poj.org/problem?id=2105

看到有人写的博文,才知道的这个库函数,用一下,确实好用~

strtol: string to long int 第一个参数为要转换的字符串的指针,第二个一般不用,为出错时返回的二级指针,第三个为字符串中数字的基数,而且对于大小写字母通吃.

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 int main()
 5 {
 6     char str[10];
 7     int N;
 8     while(scanf("%d",&N)!=EOF) {
 9         while(N--) {
10             int i;
11             for(i=0;i<4;i++) {
12                 scanf("%8s",str);
13                 int t=strtol(str,0,2);
14                 printf("%d",t);
15                 if(i==3) {
16                     putchar('\n');
17                 } else putchar('.');
18             }
19         }
20     }
21     return 0;
22 }
原文地址:https://www.cnblogs.com/yangce/p/2893023.html