(TOJ 4413)IP address
描述
To give you an IP address, it may be dotted decimal IP address, it may be 32-bit binary IP address.
Is now required to give you an IP address, if the IP address is in dotted decimal output is 32-bit binary IP address,On the contrary, the output dotted decimal IP address.for example,the dotted decimal IP address 192.168.0.1,192->11000000,168->10101000,0->00000000,1->00000001,and
the result is11000000101010000000000000000001 。
输入
Multiple inputs, each input a string,the length of the string is less than 33;
输出
Outputrequirements of the subject, if you enter
an IP address in dotted
decimal, then the output32-bit binary
IP addresses, and vice versa, then the outputdotted decimal
IP address.
样例输入
192.168.0.1
样例输出
11000000101010000000000000000001
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h> char s[100];
void translate(int n) //将10进制转换为8位的二进制
{
int a[10];
int i,j;
i=0;
while(1)
{
a[i++]=n%2;
if(n/2==0) break;
n/=2;
}
i--;
for(j=1; j<8-i; j++)
{
printf("0");
}
for(j=i; j>=0; j--)
{
printf("%d",a[j]);
}
} void decimalTobinary(char *s)
{
int i,j,len,sum;
sum=0; i=0;len=strlen(s);
while(i<len)
{
if(s[i]!='.')
{
sum+=s[i]-'0';
sum*=10;
}
if(s[i]=='.' || i==len-1)
{
translate(sum/10);
sum=0;
}
i++;
}
printf("\n");
} void binaryTodecimal(char *s)
{
int sum,i,j;
sum=0;
for(i=0; i<=24; i+=8)
{
for(j=i; j<i+7; j++)
{
sum+=s[j]-'0';
sum*=2;
}
sum+=s[j]-'0';
printf("%d",sum);
if(i!=24) printf(".");
sum=0;
}
printf("\n");
} void solve()
{
char *p;
while(gets(s))
{
p=strchr(s,'.');
if(p==NULL)
{
binaryTodecimal(s);
}
else
{
decimalTobinary(s);
}
}
} int main()
{
solve();
return 0;
}
(TOJ 4413)IP address的更多相关文章
- oracle 11g rac R2 for linux change(public,vip)IP ,hostname (oracle 11g rac R2 修改公有,虚拟,私有IP,网卡)
结构如下: 说明: 节点IP,主机名的修改步骤来自ORACLE support文档: 如何修改集群的公网信息(包括 VIP) (文档 ID 1674442.1) 实验环境情况如下: 实验 节点名称 数 ...
- (回溯法)ip地址的合理性
题目: 给定一个只包含数字的字符串,通过返回所有可能有效的IP地址组合来恢复它. 例如: 给定“”, return [“255.255.11.135”,“255.255.111.35”]. (顺序无所 ...
- 网络地址转换NAT的两种模式(概念浅析)& IP溯源
由于全球IPv4地址越来越少.越来越贵,因此大到一个组织,小到一个家庭一个人都很难获得公网IP地址,所以只能使用内网地址,从而和别人共享一个公网IP地址.在这种情况下,NAT技术诞生. 翻译 NAT( ...
- python 判断字符串是否为(或包含)IP地址
下面是某个字符串是否为IP地址import re def isIP(str): p = re.compile('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5 ...
- SecureCRT无法连接虚拟机Linux—虚拟网卡(NAT方式)IP(169.254.xx.xx)无效问题
搞了一晚上,终于解决了http://blog.csdn.net/zengxianyang/article/details/50394809
- 图解TCP/IP笔记(3)——IP协议
目录 IP协议 IP寻址 IP地址组成 IP地址分类 广播地址 子网掩码 全局地址和私有地址 IP协议 跨越不同数据链路,实现两端节点之间的数据包传输 数据链路:只负责某一个区间之间的通信传输 IP协 ...
- Dubbo入门到精通学习笔记(八):ActiveMQ的安装与使用(单节点)、Redis的安装与使用(单节点)、FastDFS分布式文件系统的安装与使用(单节点)
文章目录 ActiveMQ的安装与使用(单节点) 安装(单节点) 使用 目录结构 edu-common-parent edu-demo-mqproducer edu-demo-mqconsumer 测 ...
- 客户端(Winform窗体)上传文件到服务器(web窗体)简单例子
客户端:先创建一个winform窗体的应用程序项目 项目结构
- 网络通信协议八之(传输层)TCP协议详解
传输层协议 分段是为了提高传输效率,封装是指给每个数据段添加一个编号 端到端的传输是逻辑上的端到端,并不是真正意义上的发送方某层与接收方某层之间的传输 IP协议只是保证数据报文发送到目的地,为主机之间 ...
随机推荐
- mysql 创建和删除用户
1.远程登录mysql mysql -h ip -u root -p 密码 2.创建用户 格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码 ...
- USBWebServer 中文便携版 快速搭建 PHP/MySQL 网站服务器环境
如果你是一位 WEB 开发者,或正在学习网页编程,你一定会发现,每到一台新电脑上想要在本地调试测试/运行网站代码都得搭建配置一遍 WAMP (Win.Apache.PHP.MySQL) 环境简直烦透了 ...
- C#实现http协议支持上传下载文件的GET、POST请求
C#实现http协议支持上传下载文件的GET.POST请求using System; using System.Collections.Generic; using System.Text; usin ...
- Thinkphp5笔记二:创建模块
系统:window 7 64位 Thinkphp版本:5.0.5 环境:wampserver集成 我的项目是部署在本地www/thinkphp 目录下.在做之前,先要考虑清楚,你需要几个模块来完成你 ...
- C++ 保存Excel文件(带密码保护)
最近有客户需求报表保存为xls的功能,需要保存的文件设置密码保护,特进行尝试! Workbook.SaveAs method (Excel) 参数详情:https://docs.microsoft.c ...
- mysql压缩版的安装教程
1. 首先创建 my.ini,在mysql解压目录下的bin文件夹中新建一个名为 my.ini 的文件,内容为 [client] port=3306 default-character-set ...
- linux中显示有颜色的字符
https://blog.csdn.net/weixin_42867972/article/details/81700469 # 设置命令提示符 PS1="\033[33;1m[\033[3 ...
- 第二种方式,修改python unittest的执行顺序,使用猴子补丁
1.按照测试用例的上下顺序,而不是按方法的名称的字母顺序来执行测试用例. 之前的文章链接 python修改python unittest的运行顺序 之前写的,不是猴子补丁,而是要把Test用例的类名传 ...
- js中的string.format
String.prototype.format = function(args) { var result = this; if (arguments.length > 0) { if (arg ...
- VB2010新特性
1.取消了连接符(1)","之后(2)"()"前后(3)"{}"前后(4)XML(5)连接字符"&"后(6)赋值 ...