IP Address


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Suppose you are reading byte streams from any device, representing IP addresses. Your task is to convert a 32 characters long sequence of '1s' and '0s' (bits) to a dotted decimal format.
A dotted decimal format for an IP address is form by grouping 8 bits at a time and converting the binary representation to decimal representation. Any 8 bits is a valid part of an IP address. To convert binary numbers to decimal numbers remember that both
are positional numerical systems, where the first 8 positions of the binary systems are:

27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1

Input

The input will have a number N (1 <= N <= 9) in its first line representing the number of streams to convert. N lines will follow.

Output

The output must have N lines with a doted decimal IP address. A dotted decimal IP address is formed by grouping 8 bit at the time and converting the binary representation to decimal representation.

Sample Input

4

00000000000000000000000000000000

00000011100000001111111111111111

11001011100001001110010110000000

01010000000100000000000000000001

Sample Output

0.0.0.0

3.128.255.255

203.132.229.128

80.16.0.1

——————————————————————————————————

给出一个32位二进制,化成点分十进制的IP地址形式

8位一处理即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <functional>
#include <bitset>
#include <string> using namespace std; #define LL long long
#define INF 0x3f3f3f3f int main()
{
int T;
char s[1000];
int a[10];
scanf("%d",&T);
while(T--)
{
scanf("%s",s);
a[8]=1;
for(int i=7;i>0;i--)
a[i]=2*a[i+1];
int a1=0,a2=0,a3=0,a4=0;
int cnt;
cnt=1;
for(int i=0;i<8;i++)
{
a1+=(s[i]-'0')*a[cnt++];
}
cnt=1;
for(int i=8;i<16;i++)
{
a2+=(s[i]-'0')*a[cnt++];
}
cnt=1;
for(int i=16;i<24;i++)
{
a3+=(s[i]-'0')*a[cnt++];
}
cnt=1;
for(int i=24;i<32;i++)
{
a4+=(s[i]-'0')*a[cnt++];
}
printf("%d.%d.%d.%d\n",a1,a2,a3,a4); }
return 0;
}

ZOJ2482 IP Address 2017-04-18 23:11 44人阅读 评论(0) 收藏的更多相关文章

  1. PAT甲 1029. Median (25) 2016-09-09 23:11 27人阅读 评论(0) 收藏

    1029. Median (25) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given an incr ...

  2. POJ3281 Dining 2017-02-11 23:02 44人阅读 评论(0) 收藏

    Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and dri ...

  3. RedHat Enterprise Linux 6.4使用Centos 6 的yum源 分类: 服务器搭建 Nginx 2015-07-14 14:11 5人阅读 评论(0) 收藏

    转载自:http://blog.sina.com.cn/s/blog_50f908410101cto6.html 思路:卸载redhat自带yum,然后下载centos的yum,安装后修改配置文件 1 ...

  4. Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏

    A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...

  5. highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏

    /*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...

  6. C#期末大作业 消消乐 2017-06-01 18:11 275人阅读 评论(0) 收藏

    邻近期末,忙于刷题之余意识到期末大作业来不及了,匆匆赶下了作业,虽说做的很是粗糙,但完全原创的 下载链接 https://pan.baidu.com/s/1cCNLr4 大体的做大约3天完成了: 第一 ...

  7. 用Apache Ivy实现项目里的依赖管理 分类: C_OHTERS 2014-07-06 18:11 564人阅读 评论(0) 收藏

    Apache Ivy是一个管理项目依赖的工具. 它与Maven  Apache Maven 构建管理和项目管理工具已经吸引了 Java 开发人员的注意.Maven 引入了 JAR 文件公共存储库的概念 ...

  8. Hdu2204 Eddy's爱好 2017-06-27 16:11 43人阅读 评论(0) 收藏

    Eddy's爱好 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Subm ...

  9. 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏

    动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...

随机推荐

  1. jQuery:总体掌握

    链式编程....方法多,属性无法得到对象进行链式.vs10自动完成.书籍锋利的jQuery vsdoc有智能提示开发时候用,开发完之后,换成min压缩版的. 经验:打开网站文件夹.可以把vs网站上的解 ...

  2. sql一个题的解法分析讲解

    本篇讲述的是对一个sql面试题的细致语法讲解.关于执行流程(on where),内连接,外连接(左右)上实用.关于这些基本的语法知识请参考我前面的sql基本语法. S(SNO,SNAME)学生学号,姓 ...

  3. scala-学习 2

    列表操作 List() 或者是 Nil 空list scala> val a = List() a:List[Nothing] = List() print(a.length) a.length ...

  4. GBDT 将子树结果当成lr输出

    http://scikit-learn.org/stable/auto_examples/ensemble/plot_feature_transformation.html#example-ensem ...

  5. Python修改文件的两种方法

    目录: 一.以占用内存的方式修改文件 二.以占用硬盘的方式修改文件 引言 文件修改的方法从操作方式上大致可以分为两类,一种是以占用电脑内存的方式,将文件读取到内存中修改再存回硬盘:第二种方法是分别打开 ...

  6. 【Java杂记】Equals 和 hashCode

    equals 和 hashCode含义 equal:判断两个对象是否相等,如果相同,返回true 否则返回false hashcode: 返回一个int数 Object 默认(内部地址转化为一个数字) ...

  7. git hg提交拉取

    工作总结web_acl 535 git clone “ssh://git@outergit.yonyou.com:49622/esn_web/web_acl.git" 600 git bra ...

  8. Zabbix安装(server和agent)及基本配置

    简介 zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制 ...

  9. The value for the useBean class attribute is invalid.

    报错如下: The value for the useBean class attribute com.JavaBeanTest is invalid. 解决方法: 在JavaBean代码中加入无参数 ...

  10. 手机屏幕左下角显示Fastboot mode是什么情况?

    刚给老婆买了一个多月的魅蓝NOTE,几天前开不了机,黑屏但左下角显示:Fastboot mode…….无论按电源键还是电源键加音量加键进行重置都没有任何作用,关后自己会重启黑屏左下角显示Fastboo ...