博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LightOJ - 1354 IP Checking
阅读量:6488 次
发布时间:2019-06-24

本文共 2047 字,大约阅读时间需要 6 分钟。

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

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
取数注意循环终止条件 ;
#include 
#include
int main(){ int c[5], d[5]; char a[40], b[40]; int t, Qt=1; scanf("%d", &t); while(t--) { scanf("%s%s", a, b); int indexc=0, sum=0; int lena=strlen(a); for(int i=0; i<=lena; i++) { if(a[i]=='.'||i==lena) { c[indexc++]=sum; sum=0; } else sum=sum*10+a[i]-'0'; } int indexd=0, Q=1; sum=0; int lenb=strlen(b); for(int i=lenb-1; i>=-1; i--) { if(b[i]=='.'||i==-1) { d[indexd++]=sum; Q=1; sum=0; } else { sum=sum+(b[i]-'0') *Q; Q *=2; } } int i; for(i=0; i< 4; i++) if(c[i] != d[3-i]) break; printf("Case %d: ", Qt++); if(i==4) printf("Yes\n"); else printf("No\n"); }}

 

转载于:https://www.cnblogs.com/soTired/p/5357072.html

你可能感兴趣的文章
JSP 页面传值方法总结
查看>>
再探canvas(小球实例)
查看>>
(原)torch中提示Unwritable object <userdata> at <?>.callback.self.XXX.threads.__gc__
查看>>
现在就可以使用的5个 ES6 特性
查看>>
端午遥想
查看>>
根据无向图的边邻接矩阵求任意一点到其他所有点之间的最短路径。
查看>>
leetcode - Search Insert Position
查看>>
chorme 关于flash的问题
查看>>
XMPP基本内容简单介绍
查看>>
NYOJ 38 布线问题_(解法1 Kruskal算法)
查看>>
Ajax-java中的ajax使用,以及编码问题
查看>>
Java注释模板设置详解
查看>>
Ctrl+H 浪潮Raid配置文档
查看>>
cakephp引入其他控制器封装方法
查看>>
[Spark]如何设置使得spark程序不输出 INFO级别的内容
查看>>
java上传并压缩图片(等比例压缩或者原尺寸压缩)
查看>>
ZegGraph属性含义
查看>>
git 命令
查看>>
【vue基础学习】vue.js开发环境搭建
查看>>
将数据文件从asm移到普通文件系统
查看>>