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

`----------------------------------------------------------------------------------------------------------------------------------------------------------`
`欢迎光临天资小屋：http://user.qzone.qq.com/593830943/main`

`----------------------------------------------------------------------------------------------------------------------------------------------------------`

Description

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```

```#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int N;
int i, j;
char s[117];
while(cin >> N)
{
while(N--)
{
cin>>s;
int ans[4], k = 7, l = 0;
int sum = 0;
for(i = 0; i < 32; i++)
{
sum +=(s[i]-'0')*pow(2.0,k);
k--;
if(i%8==7)
{
ans[l++] = sum;
sum = 0;
k = 7;
}
}
cout<<ans[0]<<'.'<<ans[1]<<'.'<<ans[2]<<'.'<<ans[3]<<endl;
}
}
return 0;
}```

1. [LintCode] Restore IP Address 复原IP地址

Given a string containing only digits, restore it by returning all possible valid IP address combina ...

/*===================================== IP Address Time Limit:1000MS Memory Limit:30000KB Total Subm ...

3. UVa 1590 IP网络(简单位运算)

Description   Alex is administrator of IP networks. His clients have a bunch of individual IP addres ...

4. ERROR 2003 (HY000): Can&#39;t connect to MySQL server on &#39;ip address&#39; (111)的处理办法

远程连接mysql数据库时可以使用以下指令 mysql -h 192.168.1.104 -u root -p 如果是初次安装mysql,需要将所有/etc/mysql/内的所有配置文件的bind-a ...

5. oracle 11g RAC安装节点二执行结果错误CRS-5005: IP Address: 192.168.1.24 is already in use in the network

[root@testdb11b ~]# /u01/app/oraInventory/orainstRoot.sh Changing permissions of /u01/app/oraInvento ...

By default, an instance in a nondefault VPC is not assigned a public IP address, and is private.You ...

7. Ubuntu setup Static IP Address

Change Ubuntu Server from DHCP to a Static IP Address If the Ubuntu Server installer has set your se ...

8. How to configure a static IP address on CentOS 7(CentOS7静态IP地址设置)

Question: On CentOS 7, I want to switch from DHCP to static IP address configuration with one of my ...

9. Azure China (8) 使用Azure PowerShell创建虚拟机，并设置固定Virtual IP Address和Private IP

<Windows Azure Platform 系列文章目录> 本文介绍的是由世纪互联运维的Windows Azure China. 相比于Global Azure (http://www ...

## 随机推荐

1. monkey命令选项参考

基本参数:     --help              打印帮助消息 -v  可以在命令行中出现多次,每次一个-V选项都会增加monkey向命令行打印输出的详细级别.默认的级别0只会打印启动信息. ...

2. web.xml中监听器配置

<!-- 监听器的配置:监听器配置完以后,应用系统在启动的时候就会开启这些监听器. 监听器的理解:监听器好比一个卫兵,卫兵一直站在那里等待长官的命令,当卫兵收到长官的命令以后,立即执行 之前已经 ...

3. 自动生成Mapper和Entity工具MybatisGenerator的使用

新建一个XML文件crmGeneratorConfig.xml,文件具体内容如下.把MybatisGenerator.zip解压出来,把MybatisGenerator文件夹复制到Eclipse安装目 ...

4. 如何配置使用 Log4j

最近在用Java 写一个FTP上传下载文件工具,正好需要产生操作日志. 利用Log4j.jar可以轻松解决.下面介绍一下Log4j的使用,具体概念到官网查阅: -------------------- ...

5. 关于帝国cms 列表页SEO优化的问题

一般列表页面中,我们都需要带分页信息区分当前页号,为区分第一页,和第一页后的其他所有分页页面.我们推荐的做法为:第一页显示正常的标题,从第二页开始便显示xxxxx-第2页-xxxx网.做法是.修改帝国 ...

6. Xmind Pro 3.4.0.201311050558 Xmind 3.4 破解版 Crack

其实就一个附件.某大神那里的下不到了.从这里就好了. 使用方法请参见压缩包~ 如果连接不能用了请及时告知回复.>< 仅适用于与版本号为201311050558的Xmind.当然尊重正版开发 ...

7. LaTeX手动安装宏包（package）以及生成帮助文档的整套流程

注意:版权所有,转载请注明出处. 我使用的是ctex套装,本来已经自带了许多package,但是有时候还是需要使用一些没有预装的宏包,这时就需要自己安装package了.下载package可以从CTA ...

8. 【转】JAVA中的浅拷贝和深拷贝

原文网址:http://blog.bd17kaka.net/blog/2013/06/25/java-deep-copy/ JAVA中的浅拷贝和深拷贝(shallow copy and deep co ...

9. 内存泄露分析 打开run static analyzer