首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >poj 2105 IP Address

poj 2105 IP Address

作者头像
xindoo
发布于 2021-01-22 12:54:51
发布于 2021-01-22 12:54:51
5220
举报
文章被收录于专栏:XINDOO的专栏XINDOO的专栏

题目链接

代码语言:javascript
复制
//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;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2013-05-27,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档