zoukankan      html  css  js  c++  java
  • lightoj--1354-- IP Checking(水题)

    Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

    Submit Status

    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

    Source

    Problem Setter: Jane Alam Jan

    Submit Status

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    int a[4];
    char str[50];
    int main()
    {
    	int t;
    	scanf("%d",&t);
    	int Case=1;
    	while(t--)
    	{
    		memset(str,'',sizeof(str));
    		memset(a,0,sizeof(a));
    		scanf("%d.%d.%d.%d",&a[0],&a[1],&a[2],&a[3]);
    		str[0]='.';
    //啊,真是打脸,我从最后一位判断,但是我竟然忘了,第一位不是‘.’,wa了n次 
    		scanf("%s",str+1);
    		int j=3,flog=0,sum=0;
    		int k=0;
    		for(int i=strlen(str)-1;i>=0;i--)
    		{
    			if(str[i]=='1')
    			sum+=pow(2,k);
    			else if(str[i]=='.') 
    			{
    				if(sum!=a[j])
    				{
    					flog=1;break;
    				}
    				sum=0;k=0;j--;
    				continue;
    			}
    			k++;
    		}
    		printf("Case %d: ",Case++);
    		if(flog) printf("No
    ");
    		else printf("Yes
    ");
    	}
    	return 0;
    }


  • 相关阅读:
    JDK Base64编解码1.7和1.8的坑
    nacos部署注意点
    详解CurrentHashMap之预习篇
    SpringBoot爬坑系列
    开发之缓存与数据库优化
    jreble备注
    Unable to open debugger port (127.0.0.1:55119): java.net.SocketException "Socket closed"
    ConcurrentHashMap源码分析
    为什么要先高16位异或低16位再取模运算
    HashMap(三)之源码分析
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273747.html
Copyright © 2011-2022 走看看