HDOJ1020 Encoding
Problem Description
Given a string containing only ‘A’ - ‘Z’, we could encode it using the following method:
Each sub-string containing k same characters should be encoded to “kX” where “X” is the only character in this sub-string.
If the length of the sub-string is 1, ‘1’ should be ignored.
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 of only ‘A’ - ‘Z’ and the length is less than 10000.
Output
For each test case, output the encoded string in a line.
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
简单的字符串题目
需要注意的只有
如果输入:AABBBAAA
输出的是:2A3B3A
而不是:5A3B
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int s,i,j,n,p,m;
char a[100000],temp;
scanf("%d",&s);
while(s--)
{
scanf("%s",a);
n=strlen(a);
temp=a[0];
m=1;
for(i=1;i<=n;i++)
{
p=1;
if(a[i]==temp)
{
m++;
}
if(a[i]!=temp)
{
p=0;
temp=a[i];
}
if(p==0)
{
if(m==1)
printf("%c",a[i-1]);
else
printf("%d%c",m,a[i-1]);
m=1;
}
}
printf("\n");
}
return 0;
}
HDOJ1020 Encoding的更多相关文章
- encoding(hdoj1020)
Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...
- javac -encoding utf8 in linux
由于另外负责编码的同事用的是utf-8,我用的默认的编码格式gbk,在提交代码时,为了迁就他,我打算把格式用工具转成utf-8. 转化成果后,然后在make一下,发现javac -encoding u ...
- 创建Odoo8数据库时的“new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)“问题
Odoo8创建数据库时,显示如下错误信息: DataError: new encoding (UTF8) is incompatible with the encoding of the templa ...
- Node.js Base64 Encoding和Decoding
如何在Node.js中encode一个字符串呢?是否也像在PHP中使用base64_encode()一样简单? 在Node.js中有许多encoding字符串的方法,而不用像在JavaScript中那 ...
- java Properties异常:Malformed \uxxxx encoding.
昨天项目中遇到一个 java.lang.IllegalArgumentException: Malformed \uxxxx encoding.这样的一个异常,debug了一下发现是读取propert ...
- svn: Can't convert string from 'UTF-8' to native encoding 的解决办法(转)
http://www.cnblogs.com/xuxm2007/archive/2010/10/26/1861223.html svn 版本库中有文件是以中文字符命名的,在 Linux 下 check ...
- C# 字符编码类Encoding
在网络通信中,很多情况下都是将字符信息转成字节序列进行传输.将字符序列转为字节序列的过程称为编码.当这些字节传送到接收方,接收方需要逆向将字节序列转为字符序列.这个过程就是解码. 常见编码有ASCII ...
- 字符集和字符编码(Charset & Encoding)
字符集和字符编码(Charset & Encoding)[转] 1.基础知识 计算机中储存的信息都是用二进制数表示的:而我们在屏幕上看到的英文.汉字等字符是二进制数转换之后的结果.通俗的说,按 ...
- 使用英文版eclipse保存代码,出现some characters cannot be mapped using "Cp1251" character encoding.
some characters cannot be mapped using "Cp1251" character encoding. 解决办法:方案一: eclipse-> ...
随机推荐
- C#DbHelperOleDb,Access数据库帮助类 (转载)
主要功能如下数据访问抽象基础类 主要是访问Access数据库主要实现如下功能 .数据访问基础类(基于OleDb)Access数据库, .得到最大值:是否存在:是否存在(基于OleDbParameter ...
- c++ 中关于int,unsigned int , short的关系与应用
转载:http://www.cppblog.com/xyjzsh/archive/2010/10/20/130554.aspx?opt=admin int类型比较特殊,具体的字节数同机器字长和编译 ...
- js中eval函数
后台数据 // 回显复选框用 List<Long> tempRoles = new ArrayList<Long>(); @SuppressWarnings("unc ...
- MORE ABORT AWR?
For some time, Oracle’s solution in this area has been its built-in tool, Statspack.Oracle Database ...
- 来讲讲C#中的类
1.什么是类? 面向对象的语言,最基本的就是类.在C#中,类是这样来定义的:类代表一组具有公共属性和行为的对象. 举个例子,现实生活中,人就是一个“类”,但这只是一个统称,指所有的人.我们要找个人一起 ...
- jQuery AJAX load() 方法
jQuery load() 方法 jQuery load() 方法是简单但强大的 AJAX 方法. load() 方法从服务器加载数据,并把返回的数据放入被选元素中. 语法: $(selector). ...
- ACM YTU 十进制与八进制的转换 (栈和队列) STL栈调用
十进制与八进制的转换(栈和队列) Description 对于输入的任意一个非负十进制整数,利用栈打印输出与其等值的八进制数. Input 111 Output 157 Sample Input 14 ...
- iframe中的各种跳转方法(转)
一.背景A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,在D中跳转页面的写法区别如下. 二.JS跳转window.location.href.locatio ...
- VC++ 17、18课
进程间通信的四种方式: 剪贴板 匿名管道 命名管道 邮槽 容器和服务器程序 容器应用程序是可以嵌入或链接对象的应用程序.word就是容器应用程序. 服务器应用程序是创建对象并且当对象呗双击时,可以被启 ...
- 初试jQuery EasyUI
jQuery EasyUI jQuery EasyUI是一组基于jQuery的UI插件集合,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面.开发者不需要 ...