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 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
随机推荐
- java 中 sleep(1000) 和 wait(1000) 的区别?
1.首先 sleep 方法是Thread类中的静态方法,他的作用是使当前线程暂时睡眠指定的时间,可以不用放在synchronized方法或者代码块中,但是 wait 方法是Object类的方法,它是使 ...
- php的post和get方法
<?php function post($url,$fields) { $fields_string = ''; foreach($fields as $key=>$value) { $f ...
- ubuntu安装svn manager
环境:系统ubuntu14.04 0. 更新软件库 sudo apt-get update sudo apt-get upgrade -y 1. 安装apache,svn,svn的apache模块 s ...
- Matlab使用心得
1..*和*的区别 .*只能用于两个同型矩阵相乘,且是相对应的元素做乘法运算,其运算规则和我们线性代数里的乘法规则是不一样的:而*用于两个矩阵相乘,如mxn,nxk两个矩阵相乘,它的运算规则和线性代数 ...
- SGU481 Hero of Our Time
Description Saratov ACM ICPC teams have a tradition to come together on Halloween and recollect terr ...
- RWD
http://webdesignerwall.com/tutorials/responsive-design-with-css3-media-queries http://www.webdesigns ...
- 【重要版本】Firefly alpha beta v1.2.2 正式发布
原地址:http://bbs.gameres.com/thread_220175.html firefly 1.2.2 更新 更新内容: 功能添加 1.动态模块更新 2.部分b ...
- SpeedPHP关于一对一和一对多关联关系的建立 model建立
新闻表:t_news 新闻类型表:b_type_to_name 其中一个新闻类型可以包含多个新闻(hasmany),一个新闻只能属于一种新闻类型(hasone) 下面是新闻model类: <?p ...
- 使用NSURLSession获取网络数据和下载文件
使用NSURLSession获取网络数据 使用NSURLSession下载文件
- easyui源码翻译1.32--ComboBox(下拉列表框)
前言 扩展自$.fn.combo.defaults.使用$.fn.combobox.defaults重写默认值对象.下载该插件翻译源码 下拉列表框显示一个可编辑文本框和下拉式列表,用户可以选择一个值或 ...