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,'\0',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\n");
else printf("Yes\n");
}
return 0;
}

lightoj--1354-- IP Checking(水题)的更多相关文章

  1. LightOJ - 1354 - IP Checking(进制)

    链接: https://vjudge.net/problem/LightOJ-1354 题意: An IP address is a 32 bit address formatted in the f ...

  2. 1354 - IP Checking(水题)

    1354 - IP Checking   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...

  3. light oj 1354 - IP Checking

    1354 - IP Checking   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...

  4. poj 2105 IP Address(水题)

    一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...

  5. LightOJ 1248 Dice (III) (水题,期望DP)

    题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...

  6. lightoj 1020 (博弈水题)

    lightoj 1020 A Childhood Game 链接:http://lightoj.com/volume_showproblem.php?problem=1020 题意:一堆石子有 m 个 ...

  7. LightOJ 1023 Discovering Permutations 水题

    http://www.lightoj.com/volume_showproblem.php?problem=1023 题意:26字母全排列 思路:用next_permutation或者思维想一下都可以 ...

  8. 二分--LIGHTOJ 1088查找区间(水题)

    #include <iostream> #include <cstdio> #include <cmath> using namespace std; const ...

  9. LightOJ 1214 Large Division 水题

    java有大数模板 import java.util.Scanner; import java.math.*; public class Main { public static void main( ...

  10. LightOJ 1220 Mysterious Bacteria 水题

    暴力就行了,找出素因子,正的最多是30,然后负的最多是31(这一点wa了一次) #include <cstdio> #include <iostream> #include & ...

随机推荐

  1. springmvc-servlet.xml 第二种选择

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. 初学struts2杂乱笔记

    1.在web.xml文件里定义struts2里的一个过滤类org.apache.struts2.dispatcher.FilterDispatcher 2.在src目录下创建struts.xml文件, ...

  3. C++关键字简述

    ID 范畴 关键字 说明 1 数据类型 bool 基本类型—-布尔类型 2 数据类型 char 基本类型—-字符类型 3 数据类型 wchar_t 基本类型—-宽字符类型 4 数据类型 double ...

  4. Qt5.2 for Android 配置及部署到手机运行

    使用DNK编程也没有那么难,使用QT为安卓跨平台编程需要安装NDK,SDK通过NDK调用C++程序,偶尔能提高一些效率. SDK下载地址:http://developer.android.com/sd ...

  5. springmvc中freemarker的搭建

    在springmvc框架已经搭好的前提下,导入freemarker.jar,此处版本是2.3. 主要的配置工作都在spring-servlet.xml中,请看代码: <!--配置试图解析器 -- ...

  6. jquery的语法

    $(this).hide() - 隐藏当前元素 $("p").hide() - 隐藏所有段落 $(".test").hide() - 隐藏所有 class=&q ...

  7. websocket 进阶!netty框架实现websocket达到高并发

    引言: 在前面两篇文章中,我们对原生websocket进行了了解,且用demo来简单的讲解了其用法.但是在实际项目中,那样的用法是不可取的,理由是tomcat对高并发的支持不怎么好,特别是tomcat ...

  8. iOS,android 常用命令

    iOS 常用命令: https://blog.csdn.net/ilikekand17/article/details/81907179 https://www.jianshu.com/p/72c62 ...

  9. vue的计算属性get和set

    1.计算属性是用来存储数据,但具有以下几个特点: a.数据可以进行逻辑处理操作. b.对计算属性中的数据进行监视. 2.计算属性和普通属性的区别: a.计算属性是基于它的依赖进行更新的,只有在相关依赖 ...

  10. nginx的headers_more模块的使用

    nginx的headers_more模块用于 添加.修改或清除 请求/响应头,该模块不是nginx自带的,默认不包含该模块,需要另外安装.幸运的是openresty默认包含了该模块,可以直接使用. 该 ...