• light oj 1354


    1354 - IP Checking
    Time Limit: 2 second(s) Memory Limit: 32 MB

    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<stdio.h>
    #include<string.h>
    #include<math.h> 
    #define LL long long
    int main()
    {
    	int t,k,i;
    	scanf("%d",&t);
    	int a,b,c,d;
    	char s[1100];
    	k=1;
    	while(t--)
    	{
    		scanf("%d.%d.%d.%d",&a,&b,&c,&d);
    		scanf("%s",s);
    		int flag=1,sum=0;
    		for(i=0;i<8;i++)
    		{
    			if(s[i]=='1')
    			    sum+=pow(2,8-1-i);
    		}
    		if(sum!=a)
    		    flag=0;
    		sum=0;
    		for(i=9;i<17;i++)
    		{
    			if(s[i]=='1')
    			    sum+=pow(2,17-1-i);
    		}
    		if(sum!=b)
    		    flag=0;
    		sum=0;
    		for(i=18;i<26;i++)
    		{
    			if(s[i]=='1')
    			    sum+=pow(2,26-1-i);
    		}
    		if(sum!=c)
    		    flag=0;
    		sum=0;
    		for(i=27;i<35;i++)
    		{
    			if(s[i]=='1')
    			    sum+=pow(2,35-1-i);
    		}
    		if(sum!=d)
    		    flag=0;
    		sum=0;
    		printf("Case %d: ",k++);
    		if(flag)
    		    printf("Yes
    ");
    		else
    		    printf("No
    ");
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Java实现约瑟夫环问题
    Java实现约瑟夫环问题
    mysql远程表链接
    linux下mysql定时备份
    深入浅出RPC——浅出篇(转载)
    深入浅出RPC——深入篇(转载)
    Qt在Windows上的调试器安装与配置
    VS2015 ASP.NET5 Web项目
    jquery validate remote验证唯一性
    jQuery UI框架
  • 原文地址:https://www.cnblogs.com/tonghao/p/4949696.html
Copyright © 2020-2023  润新知