lightoj 1354 IP Checking

来源:互联网 发布:希尔伯特矩阵 编辑:程序博客网 时间:2024/05/29 17:26
                                                     IP Checking
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

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

2

192.168.0.100

11000000.10101000.00000000.11001000

65.254.63.122

01000001.11111110.00111111.01111010

Sample Output

Case 1: No

Case 2: Yes





#include <iostream>#include <cstdio>#include <cstring>#include <sstream>using namespace std;int a,b,c,d,aa,bb,cc,dd;string str,aaa,bbb,ccc,ddd;int change(string t){    int ret=0;    for(int i=0;i<t.size();i++)  ret=ret*2+t[i]-'0';    return ret;}int main(){    int T;    scanf("%d",&T);    for(int co=1;co<=T;co++)    {         scanf("%d.%d.%d.%d",&a,&b,&c,&d);         getchar();         getline(cin,str);         for(int i=0;i<str.size();i++)  if(str[i]=='.')  str[i]=' ';         stringstream ss(str);         ss>>aaa>>bbb>>ccc>>ddd;         aa=change(aaa);         bb=change(bbb);         cc=change(ccc);         dd=change(ddd);         if(a==aa && b==bb && c==cc && d==dd)  printf("Case %d: Yes\n",co);         else   printf("Case %d: No\n",co);    }    return 0;}


0 0