OpenJudge/Poj 2105 IP Address
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:27
26
25
24
23
22
21
20
128 64 32 16 8 4 2 1Input
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
01010000000100000000000000000001Sample Output
0.0.0.0
3.128.255.255
203.132.229.128
80.16.0.1Source
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的更多相关文章
- poj 2105 IP Address
IP Address Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 18951 Accepted: 10939 Desc ...
- poj 2105 IP Address(水题)
一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...
- IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏
IP Address Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19125 Accepted: 11053 Desc ...
- poj2105 IP Address(简单题)
题目链接:id=2105">http://poj.org/problem?id=2105 ----------------------------------------------- ...
- 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 ...
- 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 ...
- 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 ...
- Ubuntu setup Static IP Address
Change Ubuntu Server from DHCP to a Static IP Address If the Ubuntu Server installer has set your se ...
- 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 ...
随机推荐
- iOS开发-控件设置
一.用户界面控件共有三种基本模式:动态.静态(非动态)和被动 动态:点击它们时会发生事情——通常是出发一段自己编写的时间代码. 被动:仅用于存储用户输入的值,以备后续使用.这些控件不会触发任何操作方法 ...
- ServletContextListener 启动SPRING加载数据到缓存的应用
java 代码 public class LoadTreeForXML implements ServletContextListener { public void contextInitia ...
- 【转】于request.getSession(true/false/null)的区别
http://blog.csdn.net/gaolinwu/article/details/7285783 关于request.getSession(true/false/null)的区别 一.需求原 ...
- SQL Server笔记
SQL Server所能读取的最小单位是页,每个页8KB,8个物理上连续的页就是一个区,这样数据库中每MB就包含有16个区 堆是没有聚集索引的表.如果表格上没有聚集索引,数据行将不按任何特殊顺序存储, ...
- php删除最后一个字符
原字符串1,2,3,4,5,6, 去掉最后一个字符",",最终结果为1,2,3,4,5,6 结合运用substr和strlen两个函数实现. 代码: $str = "1, ...
- Android中文乱码彻底解决
以下是我研究的成果,希望对您有帮助: sb = new StringBuffer(); HttpEntity entity = response.getEntity(); InputStream is ...
- [AngularJS] Accessible Button Events
Often buttons need to be handled by JavaScript, and if done improperly it can lead to accessibility ...
- struts2学习笔记(5)---自己定义拦截器
什么是拦截器? struts2中拦截器分为Struts2定义好的拦截器和自己定义的拦截器. 其作用是在一个Action运行之前进行拦截,在Action运行之后又增加某些操作. 实现原理 当请求一个Ac ...
- 显示/去掉CONSOLE窗口
众所周知,控制台应用程序一般都会显示一个控制台窗口(虚拟DOS窗口),但很多时候控制台程序的执行逻辑根本不需要与用户进行交互,所以显示这个难看的窗口纯属多余,那么如何将它屏蔽掉呢?下面我向大家介绍一种 ...
- 关于Java中return和finally谁先执行.
例子一: public class A { public static void main(String[] args) { System.out.print(tt()); } public stat ...