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 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
随机推荐
- VSCode调试go
VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH% 1.问题描述 由于安装VS15 Preview ...
- 使用struts2标签<s:action无法显示引用页面问题
使用过程中参考:http://www.cnblogs.com/lihuiyy/archive/2012/03/23/2411601.html 个人使用: 1.引用页面 <s:action nam ...
- CSS3实战:让我们尽情的圆角吧
如果说,WAP2.0网页的机型.浏览器适配给我们无线制作经理造成了巨大的心理 阴影,那么从iPhone.Android这些高端手机应用 起,我们终于可以庆幸比其他同行提 前迎来了一个新时代,这两种高端 ...
- [CC150] Get all permutations of a string
Problem: Compute all permutations of a string of unique characters. 此题用循环的方式不好做,下面是一种递归的思路: 把给的字符串看成 ...
- 将cocos2dx项目从VS移植到Eclipse
本文转自:http://www.cnblogs.com/Z-XML/p/3349518.html 引言:我们使用cocos2d-x引擎制作了一款飞行射击游戏,其中创新性地融入了手势识别功能.但是我们在 ...
- [codility]tape_equilibrium
http://codility.com/demo/take-sample-test/tapeequilibrium 简单题.记录到i为止的sum就可以了.O(n). // you can also u ...
- 5. Unity脚本的执行顺序
Unity是不支持多线程的,也就是说我们必须要在主线程中操作它,可是Unity可以同时创建很多脚本,并且可以分别绑定在不同的游戏对象身上,他们各自都在执行自己的生命周期感觉像是多线程,并行执行脚本的, ...
- Delphi中一些DLL的运用(要传递Application和Screen,似乎还忘了传递提示控件)
dll 调用部分: {****************************************************************} { } { Project: DllDebug ...
- dojo 图表制作教程
http://www.sitepen.com/labs/code/charting/tutorial/tutorial1.html http://www.sitepen.com/labs/code/c ...
- Attribute的一个列子
其实在博客中也写过这个东西,也介绍过它的原理,原理很简单,就是在运行的时候通过反射拦截获取一些信息,但是我在写程序的时候几乎没用过,可能是自己接触的还不够多,也许是因为自己接触的功能不算复杂往往几句代 ...