Shorten IPv6 Address
题意:转换一个128位的二进制串,变成16进制,并且格式为x:x:x:x:x:x:x:x然后多个相邻的0变成::,且只有一个::,求变成的字典序最小且最短的字符串。
思路:大水题,但是就是一直wa,思路都一样的还是wa。先将二进制转化为十进制,然后用%x输出,因为连续的0可变短,但有优先级,首先选0长的,然后如果长度相等,先选中间,中间里面先选中间偏后,然后是最后,最后是前面。差不多就这意思吧。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define ll long long
using namespace std;
const int N = + ;
char s[N];int a[], r[];
int main() {
int T;
scanf("%d", &T);
for (int tii = ; tii <= T; tii++) {
scanf("%s", s + );
for (int i = ; i <= ; i++) {
a[i] = ;
for (int j = ; j <= ; j++) {
a[i] = a[i] * + s[(i - ) * + j] - '';
}
}
memset(r, , sizeof(r));
printf("Case #%d: ", tii);
int id = ;
for (int i = ; i > ; i--) {
if (a[i] == ) r[i] = r[i + ] + ;
if (r[id] < r[i]) id = i;
if (r[id] == r[i] && r[id] + id - == && i != ) id = i;
} for (int i = ; i <= ; i++) {
if (id == i && r[i] >= ) {
if (id == )
printf(":");
printf(":");
i += r[id] - ;
}
else {
printf("%x", a[i]);
if (i != )
printf(":");
}
}
printf("\n");
}
return ;
}
Shorten IPv6 Address的更多相关文章
- 2019牛客多校第六场 B - Shorten IPv6 Address 模拟
B - Shorten IPv6 Address 题意 给你\(128\)位的二进制,转换为十六进制. 每\(4\)位十六进制分为\(1\)组,每两组用一个\(":"\)分开. 每 ...
- 牛客多校第六场 B Shorten IPv6 Address 模拟
题意: 给你一个二进制表示的IPv6地址,让你把它转换成8组4位的16进制,用冒号分组的表示法.单组的前导0可以省略,连续多组为0的可以用两个冒号替换,但是只允许替换一次.把这个地址通过这几种省略方式 ...
- 2019 牛客多校第六场 B Shorten IPv6 Address
题目链接:https://ac.nowcoder.com/acm/contest/886/B 题目大意 给定一个 128 位的二进制 ip 地址,让你以 16 位一组,每组转成 16 进制,用冒号连接 ...
- Convert IPv6 Address to IP numbers (C#)
URL: http://lite.ip2location.com/ Use the code below to convert the IP address of your web visitors ...
- IPv6 tutorial 4 IPv6 address syntax
https://4sysops.com/archives/ipv6-tutorial-part-4-ipv6-address-syntax/ Now that you know about the n ...
- How to support both ipv4 and ipv6 address for JAVA code.
IPv6 have colon character, for example FF:00::EEIf concatenate URL String, IPv6 URL will like: http: ...
- [题解]Shorten IPv6 Address-模拟(2019牛客多校第六场B题)
题目链接:https://ac.nowcoder.com/acm/contest/886/B 题意: 您将获得一个IPv6地址,该地址是128位二进制字符串.请根据以下规则确定其最短的表示: 以十六进 ...
- golang 判断IPv4 or IPv6 address
import strings func IsIPv4(address string) bool { return strings.Count(address, ":") < ...
- 2019nc#6
https://ac.nowcoder.com/acm/contest/886#question 题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Garbage Classificatio ...
随机推荐
- HTML--JS 表单验证
<html> <head> <title>验证表单</title> <script type="text/javascript" ...
- Activation Functions and Their Derivatives
1. Sigmoid Function: when z=0,g'(z)=0.25 2. tanh Function: when x=0,tanh'(x)=1 3. Relu
- Mac006--swithchosts安装
Mac006--swithchosts安装 使用brew命令安装:brew cask install switchhosts 因为mac上,网络下载无法进行安装,所以应用brew命令安装. switc ...
- vs2010修改的内容在浏览器页面不变怎么办
解决方法1: 如果是静态页面, Ctrl+F5 强制刷新浏览器页面 解决方法2: 页面中<%@ Page Language="C#" CodeBehind="Def ...
- OSPF协议——原理及实验
首先命令部分: ospf 1 进入ospf协议 area 0 划定自治区域 因为实验只用了1个区域所以参数就为0 也就是骨干区域 network +网段+反写掩码(0.0.0.255)指定运行OSPF ...
- JavaScript.Remove
Array.prototype.remove = function (from, to) { var rest = this.slice((to || from) + 1 || this.le ...
- spring-第十七篇之spring AOP基于注解的零配置方式
1.基于注解的零配置方式 Aspect允许使用注解定义切面.切入点和增强处理,spring框架可以识别并根据这些注解来生成AOP代理.spring只是用了和AspectJ 5一样的注解,但并没有使用A ...
- webpack2.0 基本使用
webpack是一款前端模块打包工具, 它的出现是由于现代web开发越来越复杂,如果还是像原来那样把所有的js代码都写到一个文件中,维护非常困难.而解决复杂化的方法通常是分而治之,就是把复杂化的东西进 ...
- python学习二十三天函数的定义
在计算机编程中,函数就是可以重复调用,可以传递参数,减少代码的量,可以高效写出好的代码,提高软件的运行质量,下面简单讲述python函数的定义方式 1,函数的定义 函数的定义用关键词def 函数名跟 ...
- mpvue 无法获取$store的问题
在开发的时候,我们喜欢将一些公共的方法,属性,放在一个特定的位置,例如在mpvue开发小程序的时候, 我们将其放在 vue提供的store里面,或者在mainjs中通过Vue.prototype.xx ...