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 ...
随机推荐
- Shell中uname命令查看系统内核、版本
uname命令 描述 用于打印内核名称和版本.主机名等系统信息. 用法 uname [OPTION]... 参数 用法 -a print all information -s print th ...
- CentOS修改网络设置,不容易啊,终于可以在virtualbox里上网了
CentOS 修改网关 修改对应网卡的网关的配置文件[root@centos]# vi /etc/sysconfig/network修改以下内容NETWORKING=yes(表示系统是否使用网络,一般 ...
- Comprehensive Guide to build a Recommendation Engine from scratch (in Python) / 从0开始搭建推荐系统
https://www.analyticsvidhya.com/blog/2018/06/comprehensive-guide-recommendation-engine-python/, 一篇详细 ...
- Mimikatz 使用学习
下载地址 https://github.com/gentilkiwi/mimikatz/ windows:https://download.csdn.net/download/think_ycx/93 ...
- mybatis 注解开发CRUD
mybatis 的常用注解说明 @Insert:实现新增 @Update:实现更新 @Delete:实现删除 @Select:实现查询 @Result:实现结果集封装 @Results:可以与@Res ...
- vuejs基础-计算器案例
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【报错】An error happened during template parsing (template: "class path resource [templates/hello1.html]")
页面显示: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing t ...
- java.lang.IllegalStateException: Cannot forward after response has been committed
jjava.lang.IllegalStateException: Cannot forward after response has been committed at org.apache.cat ...
- [poj3074]Sudoku(舞蹈链)
题目链接:http://poj.org/problem?id=3074 舞蹈链精确覆盖的经典题目,一个数独每个位置的要求,可以得到以下四个约束1.每个位置有且只有一个数字2.每个位置的数字在一行只能出 ...
- CF1105C Ayoub and Lost Array ——动态规划
CF1105C Ayoub and Lost Array 题意:一个整数数组,满足: 1. 长度为n 2. 所有元素都在[l, r]范围内 3. 所有元素的和能被3整除给出n, l, r (1 ≤ n ...