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. java多线程基本概述(一)——线程的基本认知

    1.1.概念: 进程:进程是操作系统结构的基础,是一次程序的执行:是一个程序及其数据再处理器上顺序执行时所发生的活动:是程序再一个数据集合上运行的过程,它是系统进行系统资源分配和调度的最小单元. 线程 ...

  2. CSS也需要重构

    最初接触到的CSS面向对象,是项目里的CSS超过8千行,缺乏约束和管理,在近期或不远的将来,有迫切的要求需要重构.CSS面向对象和模块化. CSS代码遇到的问题: 重用性差,看着一个CSS的名称,很难 ...

  3. KVO 模式详解

    KVO:观察者模式.当指定的被观察对象属性被修改时,允许对象接收到通知的机制. p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; ...

  4. 关于 centos 7系统,iptables透明网桥实现【转载请注明】

    首先建立网桥:(使用bridge)    示例 桥接eth0 与 eth1 网口 /sbin/modprobe bridge /usr/sbin/brctl addbr br0 /sbin/ifup ...

  5. 【外文翻译】 为什么我要写 getters 和setters

    原文作者: Shamik Mitra 原文链接:https://dzone.com/articles/why-should-i-write-getters-and-setters 当我开始我的java ...

  6. mybatis中oracle实现分页效果

    首先当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台将xml字符串转换为xml文档时报错,从而导致 ...

  7. SQL注入详细介绍及如何防范SQL注入式攻击

    一. SQL注入攻击的简单示例. statement := "SELECT * FROM Users WHERE Value= " + a_variable + " 上面 ...

  8. React学习(一)父子组件通讯

    React父子组件之间通讯,利用props和state完成,首先React是单向数据流,父组件可以向子组件传递props: 实现父子组件双向数据流整体的思路是: 1,父组件可以向子组件传递props, ...

  9. gsoap创建webservice服务简单教程

    版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] WebServicesoapgsoap 使用gsoap创建webservice服务 下载gsop 准备待导出的服务接口定义文件比 ...

  10. 大数相加a+b

    #include<stdio.h>#include<string.h>#define MAX 1000void Add(char *a,char *b,char *result ...