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 - 加密的更多相关文章

  1. hdu1020 Encoding

    http://acm.hdu.edu.cn/showproblem.php?pid=1020 过了的就是好孩子........ #include<stdio.h> #include< ...

  2. java sm4国密算法加密、解密

      java sm4国密算法加密.解密 CreationTime--2018年7月5日09点20分 Author:Marydon 1.准备工作 所需jar包: bcprov-jdk15on-1.59. ...

  3. (转)Java DES 与Base64

    原文地址http://blog.csdn.net/tomatozq/article/details/20773559 1,DES /** * 解密 * @param message * @param ...

  4. BouncyCastle 密钥转换 - Java

    转自: https://blog.csdn.net/a351945755/article/details/63707040 1. PKCS#8 转 PKCS#1 You will need Bounc ...

  5. 解决IllegalBlockSizeException:last block incomplete in decryption异常

    解决IllegalBlockSizeException:last block incomplete in decryption异常分类: webkit android最近做个加解密的实现,虽然实现了, ...

  6. Delphi与JAVA互加解密AES算法

    搞了半天终于把这个对应的参数搞上了,话不多说,先干上代码: package com.bss.util; import java.io.UnsupportedEncodingException; imp ...

  7. 转 Encoding is Not Encryption 编码和加密的区别

    昨天跟别人聊天的时候,别人把base64说成了加密. 我并不是扣字眼,但是做为一个IT技术人员我认为分辨加密和编码的区别算是一个常识. It's unfortunate that the words  ...

  8. (暴力求解)Encoding HDU1020

    Encoding 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020 Time Limit: 2000/1000 MS (Java/Others)    ...

  9. 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)

    //1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...

随机推荐

  1. 树状数组 && 线段树

    树状数组 支持单点修改 #include <cstdio> using namespace std; int n, m; ], c[]; int lowbit(int x) { retur ...

  2. win7下用SSH连接linux虚拟机

    本文来自转载:原文 [需求] 在win7环境下用SSH(SecureShell)连接本地的一台虚拟机上ubuntu(11.10)系统  [环境] win7,ubuntu,vmware(8.0) [方案 ...

  3. HDFS中NameNode启动过程

    移动到hadoop文件目录下 NameNode启动命令:sbin/hadoop-daemon.sh start namenode DataNode启动命令:sbin/hadoop-daemon.sh ...

  4. cookie,session,token的定义及区别

    参考了很多文章总结的. 1.cookie(储存在用户本地终端上的数据) 服务器生成,发送给浏览器,浏览器保存,下次请求同一网站再发送给服务器. 2.session(会话) a.代表服务器与浏览器的一次 ...

  5. 《分布式Java应用之基础与实践》读书笔记二

    远程调用方式就是尽可能地使系统间的通信和系统内一样,让使用者感觉调用远程同调用本地一样,但其实没没有办法做到完全透明,例如由于远程调用带来的网络问题.超时问题.序列化/反序列化问题.调式复杂的问题等. ...

  6. 利用Unity3D实现多平台增强现实网络游戏的一种方案

    这几天去厦门参加了VALSE2017会议,对于其中某个环节展示的有关增强现实游戏的部分印象深刻.因为前两年一度沉迷于利用各类引擎开发游戏,所以也曾经以Pokemon GO为模板开发过一款多平台增强现实 ...

  7. xmlplus 组件设计系列之一 - 图标

    网页上使用的图标分可为三种:文件图标.字体图标和 SVG 图标.对于文件图标,下面仅以 PNG 格式来说明. PNG 图标 对于 PNG 图标的引用,有两种方式.一种是直接由 HTML 元素 img ...

  8. AngularJS入门教程:日期格式化

    AngularJS入门教程:日期格式化[转载] 本地化日期格式化: ({{ today | date:'medium' }})Nov 24, 2015 2:19:24 PM ({{ today | d ...

  9. Xcode8插件安装

    一.创建一个自定义证书并且为Xcode重新签名1.打开钥匙串 2.创建自定义签名证书 3.重新签名Xcode(速度比较慢,大概要等1分钟) $ sudo codesign -f -s XcodeSig ...

  10. input元素之间的融合

    将两个input融合在一起,注意input标签之间的空格 .put1{ width: 20px; height: 28px; vertical-align:middle; border: 1px so ...