Light OJ 1354 IP Checking
2016-03-25 16:26
405 查看
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> using namespace std; int n; int a, b, c, d, e, f, g, h; char s; int bin(int x) { int lln = 1, temp = 0; while (x){ temp += x % 10 * lln; lln *= 2; x /= 10; } return temp; } int main() { int case1 = 0; scanf("%d", &n); while (n--){ scanf("%d%c%d%c%d%c%d", &a, &s, &b, &s, &c, &s, &d); scanf("%d%c%d%c%d%c%d", &e, &s, &f, &s, &g, &s, &h); printf("Case %d: ", ++case1); if (bin(e) == a && bin(f) == b && bin(g) == c && bin(h) == d) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- 委托开发合同与合作开发合同的区别
- xUtils的介绍
- 简洁的滚动鼠标 改变图片大小js
- Linux的僵尸进程处理2
- C# 中const和readonly的区别
- NGUI实现Sprite裁切成圆形或者椭圆形(不完美)
- MyEclipse Trial Expired,手动注册MyEclipse
- static使用小结
- html5-detial
- html5-detial
- 根据官方api调用百度地图定位
- php单例
- POJ 2456 Aggressive cows(二分查找 最大化最小值)
- vim 语法高亮
- jqprint 打印网页 jQuery print plugin
- hdu 2586(LCA + 节点间距离)
- React-Native 学习笔记
- MANIFEST.MF 文件内容完全详解
- UE4教程推荐
- Shader Wave