[HDU1020] Encoding - 加密
Problem Description
Given a string containing only 'A' - 'Z', we could encode it using the following method.
1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.
2. If the length of the sub-string is 1, '1' should be ignored.
给定一个只含有'A'-'Z'的字符串,我们可以用下面的方法对其进行加密:
1. 每个含有k个相同字符的子字符串应该被加密为"kX","X"是子字符串中唯一的字符。
2. 如果子字符串的长度为1,'1'应该被忽略。
Input
The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists only 'A' - 'Z' and the length is less than 10000.
第一行包含一个整数N(1 <= N <= 100)指定数据组数。接下来的N行含有N的字符串。每个字符串只含有'A'-'Z'并且长度小于10000。
Output
For each test case, output the encoded string in a line.
对于每组测试数据,用一行输出加密字符串。
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
分析
从第二个字符开始,判断它与前面是否相同。维护变量k,初始为1,如果相同k++,如果不相同则按规定输出,且k设为1。但需要注意,到了结尾还需要再次输出。
代码
Language: C
#include <stdio.h>
#include <string.h>
int main()
{
int n;
char s[];
scanf("%d", &n);
while (n--)
{
scanf("%s", s);
int l = strlen(s);
int k = ;
for (int i = ; i < l; i++)
if (s[i] == s[i - ])
k++;
else
{
if (k > )
printf("%d", k);
putchar(s[i - ]);
k = ;
}
if (k > )
printf("%d", k);
putchar(s[l - ]);
putchar('\n');
}
return ;
}
[HDU1020] Encoding - 加密的更多相关文章
- hdu1020 Encoding
http://acm.hdu.edu.cn/showproblem.php?pid=1020 过了的就是好孩子........ #include<stdio.h> #include< ...
- java sm4国密算法加密、解密
java sm4国密算法加密.解密 CreationTime--2018年7月5日09点20分 Author:Marydon 1.准备工作 所需jar包: bcprov-jdk15on-1.59. ...
- (转)Java DES 与Base64
原文地址http://blog.csdn.net/tomatozq/article/details/20773559 1,DES /** * 解密 * @param message * @param ...
- BouncyCastle 密钥转换 - Java
转自: https://blog.csdn.net/a351945755/article/details/63707040 1. PKCS#8 转 PKCS#1 You will need Bounc ...
- 解决IllegalBlockSizeException:last block incomplete in decryption异常
解决IllegalBlockSizeException:last block incomplete in decryption异常分类: webkit android最近做个加解密的实现,虽然实现了, ...
- Delphi与JAVA互加解密AES算法
搞了半天终于把这个对应的参数搞上了,话不多说,先干上代码: package com.bss.util; import java.io.UnsupportedEncodingException; imp ...
- 转 Encoding is Not Encryption 编码和加密的区别
昨天跟别人聊天的时候,别人把base64说成了加密. 我并不是扣字眼,但是做为一个IT技术人员我认为分辨加密和编码的区别算是一个常识. It's unfortunate that the words ...
- (暴力求解)Encoding HDU1020
Encoding 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020 Time Limit: 2000/1000 MS (Java/Others) ...
- 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)
//1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...
随机推荐
- 浅析 Jndi / DataSource / ConnectionPool 三者
最近有个用户量 5W-10W 的 web 应用,频繁导致 weblogic 崩溃,让运维组很难受. 通过几天跟踪系统日志和 weblogic 运行状况,发现报错的姿势有很多,其中对定位问题比较关键的报 ...
- 浩哥解析MyBatis源码(十一)——Parsing解析模块之通用标记解析器(GenericTokenParser)与标记处理器(TokenHandler)
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6724223.html 1.回顾 上面的几篇解析了类型模块,在MyBatis中类型模块包含的 ...
- js中将yyyy-MM-dd格式的日期转换
1.转换为yyyy年MM月dd日 var str = "2017-02-16"; var reg =/(\d{4})\-(\d{2})\-(\d{2})/; var date = ...
- redis skiplist (跳跃表)
redis skiplist (跳跃表) 概述 redis skiplist 是有序的, 按照分值大小排序 节点中存储多个指向其他节点的指针 结构 zskiplist 结构 // 跳跃表 typede ...
- 百度UEditor图片上传或文件上传路径自定义
最近在项目中使用到百度UEditor的图片以及文件上传功能,但在上传的时候路径总是按照预设规则来自动生成,不方便一些特殊文件的维护.于是开始查看文档和源代码,其实操作还是比较简单的,具体如下: 1.百 ...
- java获得路径的多种方式
本文讲解java语言中获得运行时路径的多种方式,包括java项目.java web项目.jar.weblogic等多种场景. 一.this.getClass().getClassLoader().ge ...
- linux基础 作业篇
1.自动部署反向代理 web nfs #!/usr/bin/python #-*- coding:utf-8 -*- #开发脚本自动部署及监控 #1.编写脚本自动部署反向代理.web.nfs: #!/ ...
- mac终端ssh连接服务器 空闲的时候 连接断开
ssh_config详解(MAC OSX) 方法1:MAC客户端配置 配置“/etc/ssh/ssh_config”文件 “/etc/ssh/ssh_config” 文件是OpenSSH系统范围的配置 ...
- Js 网页版扫雷游戏代码实现
这个游戏是自己在大约一年前联系js熟练度时做的,用的都是基础的东西,最近比较忙没时间整理.直接发给大家,有兴趣的可以看一下.欢迎大家提出建议.如果你有什么新的想法也可以提出来,或者你并不擅长编程.你想 ...
- Markdown - 语法简介
标题 在文字里书写不同数量的“#”可以完成不同的标题,如下: # 一级标题 ## 二级标题 ### 三级标题 #### 四级标题 ##### 五级标题 ###### 六级标题 列表 无序列表的使用,在 ...