LightOJ 1354 - IP Checking

1354 - IP Checking




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



题意:判断所输入的两个IP地址是否相同,下面的为2进制


思路:瞎暴力模拟就好了


ac代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
#define fab(a) (a)>0?(a):(-a)
#define MAXN 100010
#define INF 0xfffffff
using namespace std;
char a[MAXN];
char b[MAXN];
int aa[MAXN];
int bb[MAXN];
int main()
{
	int t,i;
	int cas=0;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%s",a);
		scanf("%s",b);
		int len1=strlen(a);
		int len2=strlen(b);
		memset(aa,0,sizeof(aa));
		memset(bb,0,sizeof(bb));
		int k,q=1;
		int bz;
		for(i=len1-1;i>=0;i--)
		{
			bz=0;
			k=1;
			while(a[i]!='.'&&i>=0)
			{
				aa[q]=aa[q]+((a[i]-'0')*k);
				k*=10;
				i--;
				bz=1;
			}
			//i++;
			if(bz)
			q++;
		}
		q=1;
		for(i=len2-1;i>=0;i--)
		{
			bz=0;k=1;
			while(b[i]!='.'&&i>=0)
			{
				bb[q]=bb[q]+((b[i]-'0')*k);
				k*=2;
				i--;
				bz=1;
			}
			//i++;
			if(bz)
			q++;
		}
		int flag=0;
		for(i=1;i<=4;i++)
		if(aa[i]!=bb[i])
		{
			flag=1;
			break;
		}
		printf("Case %d: ",++cas);
		if(flag)
		printf("No\n");
		else
		printf("Yes\n");
	}
	return 0;
}


你可能感兴趣的:(LightOJ 1354 - IP Checking)