POJ 2105 IP address 的两种写法,库函数的使用

来源:互联网 发布:海贼王娜美工口漫画 编辑:程序博客网 时间:2024/06/05 19:06
#include <stdio.h>#include <stdlib.h>int main(){    int i;    int j;    int k;    int n;    int d;    int t;    char c;/*    scanf("%d\n", &n);    for (i = 0; i < n; i++)    {        for (j = 0; j < 4; j++)        {            d = 128;            t = 0;            for (k = 0; k < 8; k++)            {                c = getchar() % 48;                t += d * c;                d /= 2;            }            if (j < 3)                printf("%d.", t);            else                printf("%d\n", t);        }        scanf(" \n");    }*/    char str[9];    scanf("%d", &n);    for (i = 0; i < n; i++)    {        for (j = 0; j < 4; j++)        {            scanf("%8s", str);            t = strtol(str, 0, 2);            if (j < 3)                printf("%d.", t);            else                printf("%d\n", t);        }    }    return 0;}/* strtol 函数可以把base进制的字符串转化成10进制函数。*/选自短码之美page75


原创粉丝点击