lightoj--1354-- IP Checking(水题)
| 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
#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(水题)的更多相关文章
- LightOJ - 1354 - IP Checking(进制)
链接: https://vjudge.net/problem/LightOJ-1354 题意: An IP address is a 32 bit address formatted in the f ...
- 1354 - IP Checking(水题)
1354 - IP Checking PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...
- light oj 1354 - IP Checking
1354 - IP Checking PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...
- poj 2105 IP Address(水题)
一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...
- LightOJ 1248 Dice (III) (水题,期望DP)
题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...
- lightoj 1020 (博弈水题)
lightoj 1020 A Childhood Game 链接:http://lightoj.com/volume_showproblem.php?problem=1020 题意:一堆石子有 m 个 ...
- LightOJ 1023 Discovering Permutations 水题
http://www.lightoj.com/volume_showproblem.php?problem=1023 题意:26字母全排列 思路:用next_permutation或者思维想一下都可以 ...
- 二分--LIGHTOJ 1088查找区间(水题)
#include <iostream> #include <cstdio> #include <cmath> using namespace std; const ...
- LightOJ 1214 Large Division 水题
java有大数模板 import java.util.Scanner; import java.math.*; public class Main { public static void main( ...
- LightOJ 1220 Mysterious Bacteria 水题
暴力就行了,找出素因子,正的最多是30,然后负的最多是31(这一点wa了一次) #include <cstdio> #include <iostream> #include & ...
随机推荐
- jquey中的事件绑定
三种方法: $(selector).live(events, data, handler); // jQuery 1.3+ $(document).delegate(se ...
- 我的wordpress在Nginx的配置
lnmp生成过程 You select the exist rewrite rule:/usr/local/nginx/conf/wordpress.conf Gracefully shutting ...
- equal height
https://css-tricks.com/the-perfect-fluid-width-layout/ http://nicolasgallagher.com/multiple-backgrou ...
- ubuntu16.04下编译安装OpenCV
一: 预先配置 为使OpenCV的安装在编译时更完备,预先安装好所有的开发平台: 二:编译OpenCV 在OpenCV官网下载UNIX的源码包: 安装一下软件: sudo apt-get instal ...
- SpringMVC(一) HelloWorld
学习新东西的的第一个程序--HelloWorld,以下是SpringMVC的HelloWorld 第一步: 用MAVEN 创建webapp,并添加依赖.(强烈建议使用MAVEN,MAVEN学习书籍和视 ...
- Kafka学习笔记(2)----Kafka的架构
1. 架构图 一个Kafka集群中包含若干个Broker(消息实例),Kafka支持Broker横向扩展,Broker越多,吞吐量越大,同时也包含了若干个Producer(可以是web前端产生的Pag ...
- rabbitmq基本原理(转载)
Rabbitmq基本原理(转载) MQ全称为Message Queue, 是一种分布式应用程序的的通信方法,它是消费-生产者模型的一个典型的代表,producer往消息队列中不断写入消息,而另一端co ...
- Nginx+keepalived双机热备(默认路径安装)- 基础篇
负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网站健康持续运行.关于负载均衡介绍,可以参考:linux负载 ...
- 利用vue-gird-layout 制作可定制桌面 (二)
添加资源池 根据项目需求 添加, 实例两个数据 { "mainData": [ { "x": 0, "y": 0, "w" ...
- UVALive-8138 Number Generator 概率dp+优化
题目链接:https://cn.vjudge.net/problem/UVALive-8138 题意 有一个随机数生成器,输出1-n的整数. 现在已经输出了k个数,问再取几个数才能使取出的所有数的个数 ...