当前位置:网站首页>(lightoj - 1354) IP checking (Analog)

(lightoj - 1354) IP checking (Analog)

2022-07-06 16:23:00 AC__ dream

Topic link :IP Checking - LightOJ 1354 - Virtual Judge

The question : Here are two for you ip Address , One is decimal , The other is binary , Now ask you two ip Is the address the same

This is simpler , Is to examine a binary conversion , Every ip Addresses are represented by four integers , When reading in, we'd better use scanf formatted input , We just need to compare whether the four binary numbers and decimal numbers are equal in turn .

Here is the code :

#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
int change(int x)// Will be binary x Convert to decimal  
{
	int ans=0;
	for(int i=0;;i++)
	{
		if(x&1) ans+=1<<i;
		x/=10;
		if(!x) return ans;
	}
}
int main()
{
	int T;
	cin>>T;
	int a1,a2,a3,a4,b1,b2,b3,b4;
	for(int _=1;_<=T;_++)
	{
		printf("Case %d: ",_);
		scanf("%d.%d.%d.%d",&a1,&a2,&a3,&a4);
		scanf("%d.%d.%d.%d",&b1,&b2,&b3,&b4);
		if(a1!=change(b1)||a2!=change(b2)||a3!=change(b3)||a4!=change(b4)) puts("No");
		else puts("Yes");
	}
	return 0;
} 

原网站

版权声明
本文为[AC__ dream]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131316426781.html