OpenJudge/Poj 2105 IP Address

时间:2022-09-26 11:35:31

1.链接地址:

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

http://bailian.openjudge.cn/practice/2105

2.题目:

IP Address
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 18146   Accepted: 10456

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

3.思路:

4.代码:

 #include "stdio.h"
#include "stdlib.h" int f(char input[],int start)
{
int ans=;
int i;
for(i=;i<;i++)
{
ans=ans*+(input[i+start]-'');
}
return ans;
}
int main()
{
int a,b,c,d;
int n;
int i;
char input[];
scanf("%d\n",&n);
for(i=;i<n;i++)
{
gets(input);
a=f(input,);
b=f(input,);
c=f(input,);
d=f(input,);
printf("%d.%d.%d.%d\n",a,b,c,d);
}
//system("pause");
return ;
}

OpenJudge/Poj 2105 IP Address的更多相关文章

  1. poj 2105 IP Address

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

  2. poj 2105 IP Address&lpar;水题&rpar;

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

  3. IP Address 分类: POJ 2015-06-12 19&colon;34 12人阅读 评论&lpar;0&rpar; 收藏

    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 &lpar;HY000&rpar;&colon; Can&&num;39&semi;t connect to MySQL server on &&num;39&semi;ip address&&num;39&semi; &lpar;111&rpar;的处理办法

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

  6. oracle 11g RAC安装节点二执行结果错误CRS-5005&colon; IP Address&colon; 192&period;168&period;1&period;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&lpar;CentOS7静态IP地址设置&rpar;

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

随机推荐

  1. MVC Core 网站开发(Ninesky) 2、栏目

    栏目是网站的常用功能,按照惯例栏目分常规栏目,单页栏目,链接栏目三种类型,这次主要做添加栏目控制器和栏目模型两个内容,控制器这里会用到特性路由,模型放入业务逻辑层中(网站计划分数据访问.业务逻辑和We ...

  2. AngularJS 第三天----作用域

    作用域的概念及其功能 AngularJS使用作用域的概念来充当数据模型的作用,在视图和控制器之间起着桥梁的作用.由于双向绑定的数据特性,视图的修改会更新 $scope,同样对 $scope的修改也会重 ...

  3. &lbrack;Swift系列&rsqb;001-入门准备

    [引子] 最新的苹果发布会上公布了新的苹果编程语言Swift,并且演示了Xcode 6 Beta的一些新功能. 据苹果公司称,这个新语言开放的API更多,实用起来更方便,总之是值得学习.使用,比C/o ...

  4. java与&period;net比较学习系列开发环境和常用调试技巧常用操作快捷键

    调试         F5 F11 调试运行   CTRL+F5 暂无 非调试运行   F6 不适用 编译整个解决方案   SHIFT+F6 不适用 编译当前选择的工程   SHIFT+F5 CTRL ...

  5. NYOJ 7-街区最短路径问题&lpar;曼哈顿距离&rpar;

    街区最短路径问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 一个街区有很多住户,街区的街道只能为东西.南北两种方向. 住户只可以沿着街道行走. 各个街道之间的间 ...

  6. C&plus;&plus;学习笔记36 (模板的细节明确template specialization)和显式实例(template instantiation)

    C++有时模板很可能无法处理某些类型的. 例如: #include <iostream> using namespace std; class man{ private: string n ...

  7. 在Windows平台搭建轻巧的Python开发环境——面向工程和科研的扩展包配置

    首先,下载最新版本的Python. 为什么强调最新版本呢,因为新版本的漏洞通常会少得多,而且反映了未来的趋势. 既然要学,何不起点高一点? 官方下载地址:https://www.python.org/ ...

  8. Sequelize 基本操作

    Sequelize 是 Node 的一个 ORM(Object-Relational Mapping) 框架,用来方便数据库操作. 配置 sequelize 以 mysql 为例 首先我们要引入npm ...

  9. mysql使用问题记录

    Mysql Access denied for user 'root' ERROR 1045 (28000): Access denied for user 'root'@'localhost' (u ...

  10. centos7 网卡命名

    CentOS6 及之前以太网网卡进行顺序命名的:多网卡如:eth0,eth1 依次.Centos7 则不同,命名规则默认是基于固件.拓扑.位置信息来分配.一.网卡命名的策略systemd对网络设备的命 ...