1354 - IP Checking(水题)
Time Limit: 2 second(s) | Memory Limit: 32 MB |
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.
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<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF=0x3f3f3f3f;
char s1[],s2[];
int main(){
int T,cnt=,l1,l2;
int a[],b[];
scanf("%d",&T);
while(T--){
scanf("%s%s",s1,s2);
l1=strlen(s1);l2=strlen(s2);
int temp=,k=;
for(int i=;i<l1;i++){
if(s1[i]=='.')a[k++]=temp,temp=;
else temp=temp*+s1[i]-'';
}
a[k++]=temp;
temp=;k=;
for(int i=;i<l2;i++){
if(s2[i]=='.')b[k++]=temp,temp=;
else temp=temp*+s2[i]-'';
}
b[k++]=temp;
int flot=;
for(int i=;i<;i++){
if(a[i]!=b[i])flot=;
}
if(flot)printf("Case %d: Yes\n",++cnt);
else printf("Case %d: No\n",++cnt);
}
return ;
}
最新文章
- 前端开发:css基础知识之盒模型以及浮动布局。
- Postgresql 取随机数
- hibernate复合主键
- mac与php环境
- 我的WCF学习与强化系列文章
- UVa 1339,紫书P73,词频
- kali系统安装图文教程
- Ionic Android开发环境搭建 下
- 01-05-01-1【Nhibernate (版本3.3.1.4000) 出入江湖】延迟加载及其class和集合(set、bag等)的Lazy属性配置组合对Get和Load方法的影响
- [SQL Server系] -- 基本概念
- LeetCode题解——Regular Expression Matching
- StudentSchema student实例数据库环境搭建
- 转:LR的响应时间与使用IE所感受时间不一致的讨论
- 测试开发Python培训:实现屌丝的黄色图片收藏愿望(小插曲)
- js vue 请求
- 史上最简单的SpringCloud教程 | 第五篇: 路由网关(zuul)
- Swagger UI 与SpringMVC的整合
- Red5视频流服务器安装
- 云服务设置多台tomcat开机自启动
- ftp命令大全