light oj 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\n");
else
printf("No\n");
}
return 0;
}
light oj 1354 - IP Checking的更多相关文章
- 1354 - IP Checking(水题)
1354 - IP Checking PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...
- LightOJ - 1354 - IP Checking(进制)
链接: https://vjudge.net/problem/LightOJ-1354 题意: An IP address is a 32 bit address formatted in the f ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- lwip Light Weight (轻型)IP协议
wip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈. 外文名 lwip 开发者 瑞典计算机科学院 说 明 Light Weight (轻型)I ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
随机推荐
- windows azure tools for mac
http://azure.microsoft.com/en-us/documentation/articles/xplat-cli/?fb=zh-cn http://www.windowsazure. ...
- IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送
摘要 在IOS7中设置applicationIconBadgeNumber不会有什么问题,但是直接在IOS8中设置applicationIconBadgeNumber会报错 因为在IOS8中要想设置a ...
- python 内建函数 str() 和 repr() 的区别
1.内建函数str()和repr() 或反引号操作符(``)可以方便地以字符串的方式获取对象的内容.类型.数值属性等信息. 2.str()函数得到的字符串可读性好(故被print调用) 3.repr( ...
- BigDecimal除法
public class TestDemo { public static void main(String[] args) { BigDecimal dataValue = new BigDecim ...
- UPUPW PHP环境集成包
UPUPW PHP环境集成包 http://www.upupw.net/
- SNMP中文
SNMP4J 处理中文信息时的问题 http://qsjiangs.iteye.com/blog/1966899
- MongoDB实战指南(四):MongoDB的Journaling日志功能
mongoDB的Journaling日志功能与常见的log日志是不一样的,mongoDB也有log日志,它只是简单记录了数据库在服务器上的启动信息.慢查询记录.数据库异常信息.客户端与数据库服务器连接 ...
- ANDROID_MARS学习笔记_S01原始版_010_ContentProvider
一.简介 一.代码1.xml(1)main.xml <?xml version="1.0" encoding="utf-8"?> <Linea ...
- VC2008下CRichEditView加载RichEdit4.1版本(还有一些类似的文章)
在之前的文章<RichEdit 各个版本介绍>中,写到RichEdit已经到达6.0版本了,而我们经常编程使用的却还是2.0,在vc6.0中甚至还使用1.0版本,更高的版本修复了 ...
- Android EditText如何去除边框添加下划线
(一)问题 之前的自定义EditText只能显示高度不超过屏幕高度的文本内容,继续增加内容会出现如下问题: (二)原因分析 下部(超出屏幕高度的部分)没有继续画线,也就是说横线没有画够,那么一定是循环 ...