IP Checking
Time Limit: 2000MS |
|
Memory Limit: 32768KB |
|
64bit IO Format: %lld &%llu |
Submit Status
Description
An IP address is a + bit address formatted in the following
A.b.c.d
Where A, B, C, D is integers each ranging from 0 to 255. Now you are given the IP addresses, first one in decimal form and second one in binary form, your task was to find if they is same or not.
Input
Input starts with an integer T (≤100), denoting the number of test cases.
Each case is starts with a lines. First line contains a IP address in decimal form, and second line contains a IP address in binary form. In binary form, each of the four parts contains 8 digits. Assume that the given addresses is valid.
Output
For each case, print the case number and "Yes" if they is 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
Source
Problem Setter:jane Alam The number of days to pay attention to the cyclic termination conditions;
#include <cstdio>#include<cstring>intMain () {intc[5], d[5]; Chara[ +], b[ +]; intT, qt=1; scanf"%d", &t); while(t--) {scanf ("%s%s", A, b); intIndexc=0, sum=0; intLena=strlen (a); for(intI=0; i<=lena; i++) { if(a[i]=='.'|| i==Lena) {C[indexc++]=sum; sum=0; } Elsesum=sum*Ten+a[i]-'0'; } intIndexd=0, q=1; sum=0; intlenb=strlen (b); for(inti=lenb-1; i>=-1; i--) { if(b[i]=='.'|| i==-1) {d[indexd++]=sum; Q=1; sum=0; } Else{sum=sum+ (b[i]-'0') *p; Q*=2; } } inti; for(i=0; i<4; i++) if(C[i]! = d[3-i]) Break; printf ("Case %d:", qt++); if(i==4) printf ("yes\n"); Elseprintf ("no\n"); }}
LightOJ-1354 IP Checking