zoukankan      html  css  js  c++  java
  • hdu1020 Encoding

    http://acm.hdu.edu.cn/showproblem.php?pid=1020

    过了的就是好孩子。。。。。。。。

     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<string.h>
     4 #include<stdlib.h>
     5 #include<iostream>
     6 #include<queue>
     7 using namespace std;
     8 const int N=10005;
     9 char a[N],b[N];
    10 int main()
    11 {
    12     //freopen("in.txt","r",stdin);
    13     int n;
    14     cin>>n;
    15     while(n--)
    16     {
    17         memset(a,0,sizeof(a));
    18         memset(b,0,sizeof(b));
    19         scanf("%s",a);
    20         int len=strlen(a);
    21         if(len==1)
    22         {
    23             printf("%s
    ",a);
    24             continue;
    25         }
    26         int t=0,count=0;
    27         for(int i=0;i<len;i++)
    28         {
    29             if(a[i+1]!='')
    30             {
    31                 if(a[i+1]==a[i])
    32                 {
    33                     count++;//数数
    34                     continue;
    35                 }
    36             }
    37             if(count!=0)
    38             {
    39                 count+=1;
    40                 int temp=count,k=0;
    41                 while(temp!=0)//计算位数
    42                 {
    43                     temp/=10;
    44                     k++;
    45                 }
    46                 t--;
    47                 int h=k;
    48                 while(k)
    49                 {
    50                     b[t+k]=count%10+'0';//从后赋值,123先将3赋值到b
    51                     count/=10;
    52                     k--;
    53                 }
    54                 t+=h+1;//指向
    55             }
    56             b[t++]=a[i];
    57             count=0;
    58         }
    59         b[t]='';
    60         printf("%s
    ",b);
    61     }
    62     return 0;
    63 }
  • 相关阅读:
    hdu1824-Let's go home:图论2-SAT
    acdream:Andrew Stankevich Contest 3:Two Cylinders:数值积分
    POJ 2516 Minimum Cost (KM最优匹配)
    LightOJ
    LightOJ
    HDU
    LightOJ
    LightOJ
    CodeForces
    CodeForces
  • 原文地址:https://www.cnblogs.com/xuesen1995/p/4488744.html
Copyright © 2011-2022 走看看