【字符串处理】HDOJ-1020-Encoding

【题目链接:HDOJ-1020

  相邻字符,两两比较。

 1 #include<cstdio>
 2 #include<cstring>
 3 const int MAXN = 10002;
 4 char sr[MAXN];
 5 int main(){
 6     int n;
 7     scanf("%d",&n);
 8     while(n--){
 9         scanf("%s",sr);
10         int num = 1,i;
11         for(i = 0;i < strlen(sr);i++){
12             if(sr[i] == sr[i+1]){
13                 num++;
14             }else{
15                 if(num <= 1)
16                     printf("%c",sr[i]),num = 1;
17                 else{
18                     printf("%d%c",num,sr[i]),num = 1;
19                 }
20             }
21         }
22         printf("\n");
23     }
24     return 0;
25 } 
时间: 2024-08-07 17:00:44

【字符串处理】HDOJ-1020-Encoding的相关文章

HDU 1020 Encoding 字符串

基本的字符串处理转换. 喷一喷HDU这个超级垃圾的判断系统:如果把数字存入字符串数组中输出就会错误. 如:A2B3C,如果其中的2和3保存如字符串数组中,然后输出那么就判断为WA,必须是即时输出数字2和3才算正确. 这样判我WA,哎, HDU做好点你们的判断系统吧. #include <string> #include <iostream> using namespace std; int main() { int T; string s; scanf("%d"

HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)

并不是很精简,随便改改A过了就没有再简化了. 1020. 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 c

hdu 1020 Encoding

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40214    Accepted Submission(s): 17846 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the followi

HDU 1020 Encoding 模拟

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 39047    Accepted Submission(s): 17279 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the followi

杭电 HDU 1020 Encoding

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29834    Accepted Submission(s): 13212 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the follow

HDU 1020 Encoding【连续的计数器重置】

Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51785    Accepted Submission(s): 23041 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the followi

1020 Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 45655    Accepted Submission(s): 20188 Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following method

HDU 1020 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

python 字符串的操作方法

s.captitalize()                                  首字母变大写 s.center(width  [, pad ] )                   在长度为width的字段内将字符串居中,pad是填充字符 s.count (sub [, start [ ,end ] ] )        计算指定子字符串sub的出现次数 s.decode( [encoding  [, errors]])        解码一个字符串并返回一个Unicode字

Java HttpURLConnection 抓取网页内容 解析gzip格式输入流数据并转换为String格式字符串

最近GFW为了刷存在感,搞得大家是头晕眼花,修改hosts 几乎成了每日必备工作. 索性写了一个小程序,给办公室的同事们分享,其中有个内容 就是抓取网络上的hosts,废了一些周折. 我是在一个博客上抓取的.但是这位朋友的博客应该是在做防盗链,但他的方式比较简单就是5位数的一个整形随机数.这里折腾一下就ok了. 要命的是他这个链接的流类型 居然是gzip.这个郁闷好久,一直以为是编码格式导致解析不出来结果,后来发现是gzip搞的. 主要的一段代码做个记录吧. 1 /** 2 * 网络工具类 用于