IP Address
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 18951   Accepted: 10939

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:

2

7

   2

6

  2

5

  2

4

  2

3

   2

2

  2

1

  2

0


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

Source

 
分析:
进制转换
 #include <cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
int b[]={,,,,,,,};
int main(){
int n;
string s;
while(cin>>n){
while(n--){
cin>>s;
int i,j,k=;
for(i=;i<=;){
int sum=;
j=;
while(j<){
if(s[i]=='')
sum+=b[i%];
i++;
j++;
}
cout<<sum;
if(k<){
cout<<'.';
}
else{
cout<<endl;
}
k++;
}
}
}
return ;
}

poj 2105 IP Address的更多相关文章

  1. OpenJudge/Poj 2105 IP Address

    1.链接地址: http://poj.org/problem?id=2105 http://bailian.openjudge.cn/practice/2105 2.题目: IP Address Ti ...

  2. poj 2105 IP Address(水题)

    一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...

  3. IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏

    IP Address Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19125   Accepted: 11053 Desc ...

  4. poj2105 IP Address(简单题)

    题目链接:id=2105">http://poj.org/problem?id=2105 ----------------------------------------------- ...

  5. ERROR 2003 (HY000): Can't connect to MySQL server on 'ip address' (111)的处理办法

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

  6. 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 ...

  7. Assign an Elastic IP Address to Your Instance

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

  8. Ubuntu setup Static IP Address

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

  9. 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 ...

随机推荐

  1. php数组倒叙支持多维数组

    <?php //一维数组 $test1 = array("a"=>"苹果","b"=>"香蕉",&qu ...

  2. Nutch2.2.1 问题一:索引不能提交

    按照bin/nutch下的脚步一步一步的执行抓取:Inject,Generate,Fetcher,Parse,Updatedb,Solrindex,SolrDump. 每部其实都可以打出 “bin/n ...

  3. Jenkins Pipeline+Maven+Gitlab持续集成构建问题集锦

    问题 1.全局配置一定要写正确,之前where git 给的地址时E:\Git\cmd\git.exe一直报错,其实Windows真正的git.exe在bin目录下 如果是Linux中,使用where ...

  4. c#设计模式系列:观察者模式(Observer Pattern)

    引言 在现实生活中,处处可见观察者模式,例如,微信中的订阅号,订阅博客和QQ微博中关注好友,这些都属于观察者模式的应用.在这一章将分享我对观察者模式的理解,废话不多说了,直接进入今天的主题. 观察者模 ...

  5. C++视频教程学习笔记

    1. 命名空间 用于解决命名冲突的问题 里面可以放函数.变量.结构体.类 可以嵌套 必须定义在全局作用域下 是开放的,可以随时往原先的命名空间中追加内容,而不是覆盖 实现命名空间下的函数和调用时,需要 ...

  6. “全栈2019”Java第二十四章:流程控制语句中决策语句switch下篇

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  7. javascript中children,childNodes等节点属性

    1.children与childNodes children: 获取子元素节点,无兼容问题 childnNodes: IE:获取子元素节点 非IE(chrome,Firefox等):获取子节点,包括元 ...

  8. QQ第三方登陆示例

    先上图 若想实现QQ登录,需要成为QQ互联的开发者,审核通过才可实现.注册方法可参考链接http://wiki.connect.qq.com/%E6%88%90%E4%B8%BA%E5%BC%80%E ...

  9. np.random.normal()

    高斯分布(Gaussian Distribution)的概率密度函数(probability density function): \[ f(x)=\frac1{\sqrt{2\pi}\sigma}\ ...

  10. ElasticSearch 因为磁盘空间不够引起的数据插入错误。(message [ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];]])

    ES升级到624测试从Kettle插入数据的时候,经常提示如下错误 message [ClusterBlockException[blocked by: [FORBIDDEN/12/index rea ...