HDOJ1020 Encoding

简介: 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;
}
目录
相关文章
HDOJ 1020 Encoding
HDOJ 1020 Encoding
96 0
|
人工智能
HDOJ1020 Encoding
Problem Description Given a string containing only ‘A’ - ‘Z’, we could encode it using the following method: Each sub-string containing...
658 0
|
C# Windows 存储
C#中Encoding.Unicode与Encoding.UTF8的区别
原文地址:点击打开链接 今天在园子首页看到一篇博文-简单聊下Unicode和UTF-8,从中知道了UTF-8是Unicode的一种实现方式: Unicode只是给这世界上每个字符规定了一个统一的二进制编号,并没有规定程序该如何去存储和解析。 可以说UTF-8是Unicode实现方式之一... 在闪存中记录这个收获时,@飞鸟_Asuka在回复中提了一个很好的问题:“那么在选择编码方式的时候为
1554 0
|
Web App开发 JavaScript Java
扯谈下UTF-8
前言: 本来想翻译这篇文章的(作者是utf-8编码,golang发明者之一): UTF-8: Bits, Bytes, and Benefits,http://research.swtch.com/utf8 一则翻译起来很痛苦,二则觉得这篇文章有些地方可能说得不是太明白,所以结合其它的一些东东扯谈下utf-8。
1020 0
|
机器学习/深度学习 算法 BI
转 Target Encoding之Smoothing
转 Target Encoding之Smoothing
148 0
|
PHP C++
iconv vs mb_convert_encoding
iconv 字符串按要求的字符编码来转换 string iconv ( string $in_charset , string $out_charset , string $str ) 将字符串 str 从 in_charset 转换编码到 out_charset。
1031 0
|
关系型数据库 数据库 Windows
14、utf8和UTF-8在使用中的区别
"UTF-8"是标准写法,在Windows中英文不区分大小写,所以也可以写成"utf-8"。 在数据库中只能使用"utf8"(MySQL); 静态文件使用: 总结:只有在MySQL中使用"utf-8"的别名"utf8",其他地方使用大写"UTF-8"。
804 0

热门文章

最新文章