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. LEFT JOIN与RIGHT JOIN学习笔记

    SELECT COUNT(*) FROM [tbiz_PuzzleBasic] SELECT A.BasicID,A.Name,A.Gender,B.WorkID,B.Company,B.Positi ...

  2. asp.net core 2.0类库项目读取配置文件

    1.首先在类库项目中添加 这3个库. 2.在类库项目中添加AppSetting.cs.代码如下: using Microsoft.Extensions.Configuration;using Syst ...

  3. WPF 添加OCX控件

    1. 在计算机上安装OCX控件 2.创建WPF应用程序 3.打开工具箱 4.单击COM 组件选项卡上,选择安装的控件,,然后单击确定,将控件添加到工具箱 5.在解决方案资源管理器,右键单击UserCo ...

  4. WPF 之 UI 异步交互

    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(()=> { //··················· ...

  5. jQuery为DOM动态追加事件

    处理一个列表绑定,因为是一个展示项目,没有使用复杂的插件,直接jsrender写了个模板,但是后面有一个操作按钮,去查看数据详情,想到了jquery使用on进行事件委托,然后就开搞 最初是这样写的: ...

  6. UWP平台Taglib编译(2)

    此文已由作者郑博授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验 #endif  // _WIN32 } class FileStream::FileStreamPrivate ...

  7. iOS开发应用结构化资源储备

    1.常用跳转 class 1.1 工程配置及项目初始化 1.2 超常用代码规范 1.3 一种传统的程序模块化马甲包开发架构 2.UI显示部分 UIButton UILabel UIImageView ...

  8. linux下的常用指令

    1,在vim中查找字符段 :1?字段名,此方式可以从开始向下查询字段了. :?字段名 ,查询字都段: 2,修改某个文件夹用户和组 修改文件所属用户:chown [-R] 用户 文件或目录 如:chow ...

  9. windows下webpack不是内部命令 解决方法

    安装webpack 到打包文件一路出现的各种问题 windows下webpack不是内部命令 安装完webpack后要加下环境变量 系统变量新建 NODE_PATH 变量值E:\demo\webpac ...

  10. 如何实现java的四则运算

    很多语言底层对四则运算都有内部封装, 我们还是要重复造下轮子,不为别的, 就是为了面试可以多装一分 b, 假设你已经了解了什么是二进制, 什么是异或, 什么是移位运算, 什么是与, 这些不懂就别硬上( ...