1354 - IP Checking(水题)
2015-11-08 14:14
375 查看
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<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[100],s2[100]; int main(){ int T,cnt=0,l1,l2; int a[5],b[5]; scanf("%d",&T); while(T--){ scanf("%s%s",s1,s2); l1=strlen(s1);l2=strlen(s2); int temp=0,k=0; for(int i=0;i<l1;i++){ if(s1[i]=='.')a[k++]=temp,temp=0; else temp=temp*10+s1[i]-'0'; } a[k++]=temp; temp=0;k=0; for(int i=0;i<l2;i++){ if(s2[i]=='.')b[k++]=temp,temp=0; else temp=temp*2+s2[i]-'0'; } b[k++]=temp; int flot=1; for(int i=0;i<4;i++){ if(a[i]!=b[i])flot=0; } if(flot)printf("Case %d: Yes\n",++cnt); else printf("Case %d: No\n",++cnt); } return 0; }
相关文章推荐
- lightoj LargestBox 1297 (三分)
- HDU5534 Partial Tree(15年亚洲区长春站) DP
- 意外的内存分配:JIT编译抖动
- SpingMVC IReport多数据源交叉报表示例
- java线程调度方式以及线程的状态转换讲解
- Android中activity跳转与Intent传值(重复)
- 怎么跳出 MySQL 的10个大坑(下)
- 怎么跳出 MySQL 的10个大坑(上)
- SPDY协议
- Android Studio 常用功能介绍
- ios 开发 OC编程 类的扩展 协议 延展和 类目
- 1297 - Largest Box(三分)
- 从头认识java-7.2 接口
- codeforces-478C-Table Decorations【贪心】
- Python __name__ 和 __main__
- lightoj--1294--Positive Negative Sign(水题,规律)
- lightoj--1294--Positive Negative Sign(水题,规律)
- PHPCMS调用'N'级栏目下的子栏目
- lightoj 1354 - IP Checking (进制转换)
- 数据结构之最小生成树prim算法