lightoj 1354 - IP Checking 【进制水题】
来源:互联网 发布:修改oracle默认端口 编辑:程序博客网 时间:2024/05/16 04:39
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 <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN 50000+10#define MAXM 50000000#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;char str[50];int num[5];int main(){ int t, kcase = 1; Ri(t); W(t) { Rs(str); int len = strlen(str); int top = 0, sum = 0; for(int i = 0; i < len; i++) { if(str[i] == '.') { num[++top] = sum; sum = 0; continue; } else sum = sum * 10 + str[i] - '0'; } num[++top] = sum; Rs(str); len = strlen(str); top = 0, sum = 0; int bit = 7; bool flag = true; for(int i = 0; i < len; i++) { if(!flag) break; if(str[i] == '.') { if(sum != num[++top]) flag = false; sum = 0; bit = 7; continue; } else { if(str[i] - '0' == 1) sum += (int)pow(2, bit); bit--; } } if(sum != num[++top]) flag = false; if(flag) printf("Case %d: Yes\n", kcase++); else printf("Case %d: No\n", kcase++); } return 0;}
- lightoj 1354 - IP Checking 【进制水题】
- lightoj 1354 IP Checking
- lightoj 1354 - IP Checking
- LightOJ 1354 - IP Checking
- LightOJ 1354 - IP Checking
- lightoj 1354 - IP Checking
- LightOJ 1354 IP Checking (水)
- LightOJ 1354 - IP Checking【简单模拟】
- lightoj--1354--IP Checking(水题)
- lightoj 1354 - IP Checking (进制转换)
- lightOJ 1354 - IP Checking 【字符串处理&&进制转化】
- Light OJ 1354 IP Checking
- Light OJ 1354 - IP Checking 【二进制转化】
- Light oj1354:IP Checking
- lightoj1354 - IP Checking
- light oj 1354 IP Checking【进制转换】
- lightoj 1354
- LightOJ
- R语言中如何读取Excel
- excel自动转换为可印刷版式:目录的自动生成
- 用GDB调试程序(二)
- hdu5318The Goddess Of The Moon 矩阵快速幂
- supervise进程监控工具
- lightoj 1354 - IP Checking 【进制水题】
- iPhone屏幕尺寸
- leetcode-First Missing Positive
- "升级Win10注意事项个人总结"
- atomic_t相关操作
- TwoSum1
- poj 2531 dfs(最大割)
- Hadoop操作记录(2)---完全分布式
- 直接插入排序 + 希尔排序+ 冒泡排序+ 快速排序 + 直接选择排序 + 堆排序