lightoj1354 - IP Checking
2015-11-08 17:56
399 查看
1354 - IP Checking
An IP address is a 32 bit address formatted in the following way
a.b.c.d
where a, b, c, d are integers each ranging from 0 to 255. Now you are given two IP addresses, first one in decimal form and second one in binary form, your task is to find if they are same or not.
Each case starts with two lines. First line contains an IP address in decimal form, and second line contains an IP address in binary form. In binary form, each of the four parts contains 8 digits. Assume that the given addresses are valid.
PDF (English) | Statistics | Forum |
Time Limit: 2 second(s) | Memory Limit: 32 MB |
a.b.c.d
where a, b, c, d are integers each ranging from 0 to 255. Now you are given two IP addresses, first one in decimal form and second one in binary form, your task is to find if they are same or not.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.Each case starts with two lines. First line contains an IP address in decimal form, and second line contains an IP address in binary form. In binary form, each of the four parts contains 8 digits. Assume that the given addresses are valid.
Output
For each case, print the case number and "Yes" if they are same, otherwise print "No".Sample Input | Output for Sample Input |
2 192.168.0.100 11000000.10101000.00000000.11001000 65.254.63.122 01000001.11111110.00111111.01111010 | Case 1: No Case 2: Yes |
#include<cstdio> #include<cstdlib> #include<cstring> using namespace std; char str1[100]; char str2[100]; int main() { int t,k=1,i; scanf("%d",&t); while(t--){ scanf("%s",str1); scanf("%s",str2); int I1[5]={0},I2[5]={0}; int l1=strlen(str1); int l2=strlen(str2); int d=1,n=4; for(i=l1-1;i>=0;--i){ if(str1[i]=='.'){ n--;d=1; } else { I1 +=(str1[i]-'0')*d; d*=10; } } int flag=1,m=4;d=1; for(i=l2-1;i>=0;--i){ if(str2[i]=='.'){ m--;d=1; } else { I2[m]+=(str2[i]-'0')*d; d*=2; } } for(i=1;i<=4;++i){ if(I1[i]!=I2[i]){ flag=0;break; } } if(flag){ printf("Case %d: Yes\n",k++); } else { printf("Case %d: No\n",k++); } } return 0; }
相关文章推荐
- 房产界已上市和IPO路上的难兄难弟:房天下与房多多
- 雷军是谁,他为什么而奋斗?小米上市和雷军的英雄主义
- 人生的高境界 - 无所谓
- IP网络路由技术
- 如何利用“IP地址欺骗”
- 新手看招:避免网络 IP 地址被非法修改
- 网络管理之IP地址篇
- ip地址基础知识
- 个人家园 - 永久免费ASP个人主页空间
- 脚本之家因服务器资源紧张 换了ip并升级了带宽
- IP地址组成与类型
- L.WuBi - 发布个最好用的在线五笔编码查询、五笔拆字图解
- 计算机名DNS网关IP(大家可以用来学习)
- Windows2003下批量添加和导出所有ip BAT脚本
- 用hta实现制作的无殇 - 快书V1.1打包下载了第1/2页
- Windows SP2 免激活安装版 - DeepinXP PLUS V2 测试版 下载
- 超星图书浏览器(SSReader) v4.00 Bulid 070511 - 数字图书阅览器 下载
- Convenientfox v0.0.1.3 - 基于FireFox的浏览器 下载
- GX::Transcoder v3.20.51.3687 - 音频视频文件转换全能王 下载