Light OJ 1354 - IP Checking 【二进制转化】
2015-11-08 20:15
316 查看
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.
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.
For each case, print the case number and "Yes" if they are same, otherwise print "No".
恩,就是让比较两者形式的IP是否一样。简单的二进制转化。
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".
|
|
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> using namespace std; int s[5][10]; char str[50]; int rec[9]={1,2,4,8,16,32,64,128,256}; int tran(int a[]) { int s=0; for(int i=7;i>=0;i--) s=s+a[i]*rec[7-i]; return s; } int main() { int t,a,b,c,d,cnt=0; scanf("%d",&t); while(t--) { scanf("%d.%d.%d.%d",&a,&b,&c,&d); scanf("%s",str); int len=strlen(str); int j=0; for(int i=0;i<len;++i) { int k=0; while(i<len&&str[i]!='.') { s[j][k++]=str[i]-'0'; i++; } j++; } printf("Case %d: ",++cnt); int aa=tran(s[0]); int bb=tran(s[1]); int cc=tran(s[2]); int dd=tran(s[3]); if(aa==a&&bb==b&&cc==c&&dd==d) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- Java第一次写的流布局图形界面,留个纪念
- zufe oj Problem H: 简单数学题 java
- Java第一次写的流布局图形界面,留个纪念
- ApplicationOnline_Tips&Review
- 归档
- 数据结构基础5.3:平衡二叉树(AVL树)的调整
- poj 1631 Bridging signals dp LIS
- LINUX 系统运维转向运维开发
- EasyUI - 后台管理系统 - 增加,删除,修改
- 开源消息队列系统 rabbitmq-server 安装详细
- 《大道至简》第六章读后感
- 根据分辨率改变宽度 demo
- 你不知道的JavaScript--Item29 DOM基础详解
- mysql的主从,主主,半同步
- strstr和strchr的区别
- 《大道至简》第六章读后感
- android/util中的一些常用类
- 你不知道的JavaScript--Item29 DOM基础详解
- XAMPP-1.8.3上将mediawiki-1.23.3升级到1.25.3遇到的问题
- SQLite学习手册(内置函数)