zoukankan      html  css  js  c++  java
  • HDU 1020 Encoding

    真心无力吐槽这个hdu奇怪的编译器了,本来写好好的代码,硬是说编译错误,后来仔仔细细查了半天发现一个声明没有写在最前面。。。编译器就不通过了……

    此题是我来尝试下字符串问题,解法非常简单,而且开始我想多了,其实凡是重复的字符串都是连续滴~~~

    今天虽然忙其他事情去了,不过晚上还是有精神的回来刷一题,坚持!!

    源码如下:

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main(){
     5     int n;
     6     int i,j;
     7 
     8     while(scanf("%d",&n) != EOF){
     9         while(n--){
    10             int length;
    11             char str[10001];
    12             scanf("%s",str);
    13             
    14             length = strlen(str);
    15             
    16             for(i = 0; i < length; i++){
    17                 int time = 1; //重复次数
    18                 for(j = i + 1;j < length; j++){
    19                     if (str[i] == str[j]){
    20                         time++;
    21                     }
    22                     else 
    23                         break;
    24                 }
    25                 if(time > 1){
    26                     printf("%d%c",time,str[i]);
    27                 }
    28                 else{
    29                     printf("%c",str[i]);
    30                 }
    31                 i += (time - 1);
    32             }
    33             printf("
    ");
    34         }
    35     }
    36     return 0;
    37 }
    Everything will be ok in the end. If it is not ok then it is not the end.
  • 相关阅读:
    杭电acm1517
    杭电acm1228
    杭电acm1859
    杭电acm1124
    杭电acm1327
    CPP Templates 之 template 关键字的用法技巧
    malloc与calloc区别
    CPP Templates 之 类模板的继承
    CPP Templates 之 模板演绎的注意事项
    CPP Templates 之 局部类模板特化
  • 原文地址:https://www.cnblogs.com/shirleytian/p/3203247.html
Copyright © 2011-2022 走看看