poj 2105 IP Address

简介: 题目链接
//poj 2105
//2013-05-01-21.10
#include <stdio.h>
char s[34];
int a[8] = {128, 64, 32, 16, 8, 4, 2, 1};
int main()
{
    int n;
    scanf("%d", &n);
    while (n--)
    {
        scanf("%s", s);
        int ans = 0;
        int f = 1;
        for (int i = 0; i < 32; i++)
        {
            if (s[i] == '1')
                ans += a[i%8];
            if ((i+1) % 8 == 0)
            {
                if (f)
                {
                    f = 0;
                    printf("%d", ans);
                }
                else
                    printf(".%d", ans);
                ans = 0;
            }
        }
        puts("");
    }
    return 0;
}
目录
相关文章
|
22天前
|
网络架构 开发者
|
6月前
|
存储 容器
华为机试HJ39:判断两个IP是否属于同一子网
华为机试HJ39:判断两个IP是否属于同一子网
|
8月前
|
机器学习/深度学习 网络协议 Unix
IP地址【图解TCP/IP(笔记十)】
IP地址【图解TCP/IP(笔记十)】
POJ 2105 IP Address
POJ 2105 IP Address
90 0
|
网络协议 C# 数据库
Convert IPv6 Address to IP numbers (C#)
URL: http://lite.ip2location.com/ Use the code below to convert the IP address of your web visitors and lookup for their geographical location, e.
1419 0
|
JavaScript 前端开发
|
网络协议
|
网络协议