若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1620: Encoding

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,022

题目描述

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.

输入

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.

输出

For each test case, output the encoded string in a line.

样例输入

2
ABC
ABBCCC

样例输出

ABC
A2B3C


参考代码

#include"stdio.h"
int main() 
{
    int n,i,j,m;
    char a[10010]={''},b;
    scanf("%d",&n);
    getchar();
    while(n--)
    {
        gets(a);
        for(i=0;a[i]!='';)
        {
            b=a[i];
            j=i;
            for(m=0;a[j]==b;m++,i++)
                j++;
            if(m!=1)
                printf("%d",m);
            printf("%c",b);
        }
        printf("n");
    }
    return 0;
}

解析

暂无

hustoj

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

原站点 Dreams孤独患者 Skip
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist