LightOJ - 1354 - IP Checking(进制)
链接:
https://vjudge.net/problem/LightOJ-1354
题意:
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.
思路:
直接进制转换
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 5e4+10;
const int MOD = 1e9+7;
bool Ok(int a, char *s)
{
int sum = 0;
for (int i = 0;i < 8;i++)
{
if (s[i] == '0')
continue;
sum += 1<<(7-i);
}
return a == sum;
}
int main()
{
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
char s[100];
int a, b, c, d;
printf("Case %d:", ++cnt);
scanf("%d.%d.%d.%d", &a, &b, &c, &d);
scanf("%s", s);
bool ok = true;
if (!Ok(a, s))
ok = false;
if (!Ok(b, s+9))
ok = false;
if (!Ok(c, s+18))
ok = false;
if (!Ok(d, s+27))
ok = false;
if (ok)
puts(" Yes");
else
puts(" No");
}
return 0;
}
LightOJ - 1354 - IP Checking(进制)的更多相关文章
- light oj 1354 - IP Checking
1354 - IP Checking PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...
- 1354 - IP Checking(水题)
1354 - IP Checking PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...
- Day02_IP地址详解&进制转换&DOS基本命令与批处理
学于千峰教育开源课程 感谢 千峰教育官网 b站在线视频 IP地址详解 一.简单局域网的构成 局域网:一般称为内网 简单局域网的构成:交换机.网线.PC(其他IT终端) 交换机:用来组建内网的局域网的设 ...
- IP进制站群原理
百度搜索:“inurl:0×00”,会发现全是以八进制.十六进制形式显示的域名(如下图),当点击后,浏览器会自动将这些域名转换为十进制的ip.这种方式在黑帽圈目前挺火爆的,用于做长尾词排名,可以带来可 ...
- python IP地址转16进制
python IP地址转16进制 第一种方法: 通过socket.inet_aton实现 import socket from binascii import hexlify ary='192.168 ...
- 一个小公式帮你轻松将IP地址从10进制转到2进制
网络工程师经常会遇到的一个职业问题:如何分配IP,通过子网如何捕捉某一网段或某台机器?他们甚至能够进行精准的分析和复杂的开发......凡此种种,其实与一些他们头脑中根深蒂固的常识性理论存有某种内在的 ...
- IP地址和子网划分学习笔记之《预备知识:进制计数》
一.序:IP地址和子网划分学习笔记开篇 只要记住你的名字,不管你在世界的哪个地方,我一定会去见你.——新海诚 电影<你的名字> 在我们的日常生活中,每个人的名字对应一个唯一的身(敏)份(感 ...
- ACM_“IP地址”普及(进制转换)
“IP地址”普及 Time Limit: 2000/1000ms (Java/Others) Problem Description: 大家都知道最近广财大校园网提速,现在就跟大家普及一下简单的互联网 ...
- ip地址转换成16进制long
<span style="font-size:18px;">public class IpUtil { /** * ip地址转换成16进制long * @param i ...
随机推荐
- 04 javascirpt基础知识---听课笔记
1.JavaScript概念 一门客户端脚本语言运行在客户端浏览器中的.每一个浏览器都有JavaScript的解析引擎脚本语言:不需要编译,直接就可以被浏览器解析执行了 * 功能:可以来增强用户和ht ...
- python实现查找最长公共子序列
#!/usr/bin/python # -*- coding: UTF-8 -*- worlds = ['fosh','fort','vista','fish','hish','hello','ohd ...
- day40——数据库、数据库分类、安装、修改密码、字符集编码、简单语句介绍
day40 详情请看:https://www.cnblogs.com/clschao/articles/9907529.html 数据库 数据库 简而言之可视为电子化的文件柜--存储电子文件的处所,用 ...
- crontab 定时删除
/60 * * * /bin/find /usr/local/****/****/****/****/****.log.2019* -exec rm -f {} ; >/dev/null 2&g ...
- 【LEETCODE】49、数组分类,简单级别,题目:566,1089
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- Failed to transfer file: http://repo.maven.apache.org/maven2/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar
解决办法:maven的配置文件settings.xml中添加mirror地址 <mirror> <id>alimaven</id> < ...
- go语言学习笔记----模拟实现文件拷贝函数
实例1 //main package main import ( "bufio" "flag" "fmt" "io" & ...
- winform实现图片的滑动效果
使用winform实现图片的滑动效果(类似网站首页图片滑动切换效果),结果实现了,但是效果其实不是很理想.也许有更好的方法. Timer timerSlide = null; //当前 ...
- Java Runtime.exec()用法
转自:https://www.cnblogs.com/mingforyou/p/3551199.html Java Runtime.exec()的使用 Sun的doc里其实说明还有其他的用法: exe ...
- LinuxKernel优秀博客
1.vanbreaker的专栏 2.LinuxKernel Exploration 3.DroidPhone的专栏 4.Linux内核研究以及学习文档和ARM学习以及研究的开放文档 [力荐] 5. ...