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 & ...
随机推荐
- 装饰模式(Decorator)C++实现
装饰模式 层层包装,增强功能.这就是装饰模式的要旨!装饰器模式就是基于对象组合的方式,可以很灵活的给对象添加所需要的功能.它把需要装饰的功能放在单独的类中,并让这个类包装它所要装饰的对象. 意图: 动 ...
- 有关PHP里的Cookie
会话技术:Cookie,Session: Cookie是客户端技术,服务器把每个用户的数据以Cookie的形式保存在用户各自的浏览器,当用户用浏览器再次访问服务器的web资源时则会带着各自的数据去了: ...
- 干货 | TensorFlow的55个经典案例
转自1024深度学习 导语:本文是TensorFlow实现流行机器学习算法的教程汇集,目标是让读者可以轻松通过清晰简明的案例深入了解 TensorFlow.这些案例适合那些想要实现一些 TensorF ...
- Linux系统编程@进程管理(一)
课程目标: 构建一个基于主机系统的多客户即时通信/聊天室项目 涉及的理论知识 进程控制:僵尸进程/孤儿进程.进程控制.守护进程... 进程间通信:管道.命名管道.信号... 多线程编程: 锁.信号量. ...
- Pyhhon中一些常见的字符串操作.
可变变量:list, 字典 不可变变量:元祖,字符串 字符串的操作(去掉空格, 切片, 查找, 连接, 分割, 转换首字母大写, 转换字母大小写, 判断是否是数字字母, 成员运算符(in / not ...
- 10件5G能实现,但4G不能做的事情
10件5G能实现,但4G不能做的事情 从三星Galaxy S10 5G手机到OnePlus 7 Pro 5G手机以及更高版本,首批5G手机现已上市.5G网络时代的开启是从小范围内,如果你居住在可以使用 ...
- VA Code编写html(1)
<html> <head> <title>my webside</title> <!--win+‘/’注释行--> <!--防止中文乱 ...
- JS 猴子
公园里有一只猴子和一堆桃子,猴子每天吃掉桃子总数的一半,把剩下一半中扔掉一个坏的. 到第七天的时候,猴子睁开眼发现只剩下一个桃子.问公园里刚开始有多少个桃子? <!DOCTYPE html> ...
- Django_学生管理系统
一. Django简易学生管理系统 1.在pycharm中创建工程student_manage_system,添加app:student_manage 2.配置静态文件:在工程项目目录下新建目录sta ...
- 铁大FaceBook的使用体验
铁大FaceBook是一个类似QQ和微信等聊天程序的缩小版网站,并且其针对领域较为狭窄:即只针对校园的学生和导员等人员.但其有值得推广的潜力性和可能性. 对于使用它的体验:第一点我感觉这个网站的界面很 ...