[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)://思 ...
随机推荐
- C#并行编程--命令式数据并行(Parallel.Invoke)
命令式数据并行 Visual C# 2010和.NETFramework4.0提供了很多令人激动的新特性,这些特性是为应对多核处理器和多处理器的复杂性设计的.然而,因为他们包括了完整的新的特性,开 ...
- Unity C# 多态 委托 事件 匿名委托 Lambda表达式 观察者模式 .NET 框架中的委托和事件
一.多态 里氏替换原则: 任何能用基类的地方,可以用子类代替,反过来不行.子类能够在基类的基础上增加新的行为.面向对象设计的基本原则之一. 开放封闭原则: 对扩展开放,意味着有新的需求或变化时,可以对 ...
- JAVA Struts2 搭建
java struts 2搭建 1.web工程 2.将struts2 用到的jar包,拷贝到webcontent/webinf/lib文件夹.下 3.webcontent 下的web.xml 下 ...
- Atom打造 c/c++编译环境(忙了一个上午)
众所周知 Atom是一款非常酷炫的编辑器.因为它就像上古卷轴一样,玩家可以开发各种dlc补丁,实现自己想要的效果.所以Atom 可以被你改造成自己想要的东西,可以用来写算法竞赛题目,可以开发网页,可以 ...
- 基础才是重中之重~关于ThreadStatic和Quartz的一点渊源
回到目录 ThreadStatic ThreadStatic是C#里的一个特性,它可以让你的字段在一个线程里有效,但你不能控制这个字段在何时被回收,即如果声明一个int32的字段为ThreadStat ...
- C#中 dynamic 关键字
所有表达式都能隐式的转换成dynamic,因为所有的表达式最终都能生成从Object派生出的类型. ; int b = a; //隐式转换错误 int b2 = (int)a; ; int b3 ...
- CentOS_5.6下使用cmake编译MySQL_5.5.11教程
注:资料来自网络 Centos 5.6编译安装mysql 5.5.11 2011年06月24日 星期五 05:33 MySQL 最新的版本5.5.11需要cmake编译安装,估计以后的版本也会采 ...
- 搭建自己的Git服务器
前言: GitHub是一个免费托管开源代码的远程仓库,使用起来即方便又安全,但在国内有时访问巨慢,原因你懂得.还有一些公司和个人视源码如生命,既不想开源代码又不想给Github交保护费.这时搭建一个自 ...
- 蓝桥杯-手机尾号-java
/* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2016, 广州科技贸易职业学院信息工程系学生 * All rights reserved. * 文件名称: ...
- 用java实现大文件分割、排序、合并
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundExcepti ...