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 & ...
随机推荐
- 大数据学习之路------借助HDP SANDBOX开始学习
一开始... 一开始知道大数据这个概念的时候,只是感觉很高大上,引起了我的兴趣.当时也不知道,这个东西是做什么的,有什么用,当然现在看来也是很模糊的样子,但是的确比一开始强了不少. 所以学习的过程可能 ...
- python 编码问题解决方案
1.UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128) ...
- span可编辑 属性 html 可编辑td
<span contenteditable="true">11111111111111111</span> <!DOCTYPE html PUBLIC ...
- C#读取EXCEL 并输出到文本框
#region 加载数据到DataGraidView private void button1_Click(object sender, EventArgs e) { string excelPath ...
- 企业级任务调度框架Quartz(9) Quartz之作业触发器Trigger
前序: 我们已经大概对Quartz的基本有了一个大概的认识:现在我们将要逐渐对Quartz的各个重要组件进行学习:前面已经对job进行了详细讲解,现在我们来认识下它的一个重要兄弟,没有它,作 ...
- 路飞学城Python-Day136
列举Http请求中常见的请求方式 根据HTTP标准,HTTP请求可以使用多种请求方法. HTTP1.0定义了三种请求方法: GET, POST 和 HEAD方法. HTTP1.1新增了五种请求方法:O ...
- Map之HashMap的get与put流程,及hash冲突解决方式
在java中HashMap作为一种Map的实现,在程序中我们经常会用到,在此记录下其中get与put的执行过程,以及其hash冲突的解决方式: HashMap在存储数据的时候是key-value的键值 ...
- php-fpm优化处理
php-fpm.conf有两个至关重要的参数:一个是”max_children”,另一个是”request_terminate_timeout”. 我的两个设置的值一个是”40″,一个是”900″,但 ...
- Python爬虫3-----浏览器伪装
1.浏览器伪装技术原理 当爬取CSDN博客时,会发现返回403,因为对方服务器会对爬虫进行屏蔽,故需伪装成浏览器才能爬取.浏览器伪装一般通过报头进行. 2.获取网页的报头 3.代码: import u ...
- mysql进阶练习
一 . MySQL进阶练习 /*==========================创建班级表=============================*/ CREATE TABLE class ( ...