Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22110    Accepted Submission(s): 9687

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.
 
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
 #include <stdio.h>
#include <string.h> char str[]; int main()
{
int cases;
scanf("%d",&cases);
getchar();
while(cases--)
{
int i,len,count=;
char c;
scanf("%s",str);
len=strlen(str);
i=;c=str[i];
while(i<len)
{
while(str[i+] == c)
{
count++;
i++;
}
if(count)
{
printf("%d%c",count+,c);
count = ;
c = str[i+];
}
else
{
printf("%c",c);
count = ;
c = str[i+];
}
i++;
}
printf("\n");
}
return ;
}

做过,水过!

 

hdu_1020_Encoding_201310172120的更多相关文章

随机推荐

  1. yii2的form表单用法

    使用表单 本章节将介绍如何创建一个从用户那搜集数据的表单页.该页将显示一个包含 name 输入框和 email 输入框的表单.当搜集完这两部分信息后,页面将会显示用户输入的信息. 为了实现这个目标,除 ...

  2. [Swift通天遁地]二、表格表单-(18)快速应用多种预定义格式的表单验证

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. [Swift通天遁地]四、网络和线程-(11)将服务器返回的JSON映射为实例对象

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. Centos7基本命令

    shell基本命令 linux命令行的组成结构 linux系统命令操作语法格式 命令 空格 参数 空格 文件路径或者需要处理的内容 rm   -rf   /tmp/* ls   -la   /home ...

  5. ACM_题目这么难,来局愉快的昆特牌吧

    题目这么难,来局愉快的昆特牌吧 Time Limit: 2000/1000ms (Java/Others) Problem Description: 小Z打比赛,然而比赛太难了,他坐在电脑面前被题淹没 ...

  6. 【LeetCode】-- 73. Set Matrix Zeroes

    问题描述:将二维数组中值为0的元素,所在行或者列全set为0:https://leetcode.com/problems/set-matrix-zeroes/ 问题分析:题中要求用 constant ...

  7. 回收maven私仓过期垃圾

    login->scheduled tasks->add

  8. ansible 显示运行时间

    #独家秘诀cd /etc/ansible mkdir callback_plugins cd callback_plugins wget https://raw.githubusercontent.c ...

  9. 服务器端 CentOS 下配置 JDK 和 Tonmcat 踩坑合集

    一.配置 JDK 时,在 /etc/profile 文件下配置环境变量,添加   #java environment export JAVA_HOME=/usr/java/jdk- export CL ...

  10. jQuery导航插件One-Page-Nav演示-显示命名锚记

    jQuery导航插件One-Page-Nav演示-显示命名锚记 简介 使用 选项 示例 推荐 简介 电商网站的分类比较明确,比如1楼是手机通讯产品,2楼是家用电器,3楼是服装鞋包等等,旁边还会有一个固 ...