zoukankan      html  css  js  c++  java
  • K

    ♬ Hit me, lock me up, do anything with me, ... ♬
    and Marrone, Bruno

    After thousands of years repeating the title of this problem statement, always with an excited and inviting tone, Nathan finally persuaded his colleagues to go to the karaoke. He is feeling radiant with this achievement.

    But there is a problem. After so much time trying to make his friends go to the karaoke, Nathan is afraid of embarrassing himself when he goes to sing the following classics of Brazilian music:

    • Waitress – Reginaldo Rossi
    • Blue Nightclub – Joaquim and Manuel
    • Paper Heart – Sérgio Kings
    • Love Bubble – Fagner
    • You did not teach me to forget – Fernando Mendes

    To avoid the humiliation, and to not discourage his fellows in future hang outs at the karaoke, Nathan decided to print all the song’s ciphers that are available in the karaoke, to check while he sings. However, this resulted in a colossal amount of paper, that he is not able to carry.

    But the perseverance and ingenuity of an envious programmer is not something you should underestimate.

    Nathan realized that, after all, there were only 7 musical notes. The specialists in this matter used to represent this notes with the letters A, B, C, D, E, F and G. Even more, it’s common that the same note appears several times in sequence. He decided then, to compress the songs, changing every occurrence of repeated notes with the note followed by how many times it occurs.

    For instance, given the sequence

    [(A,A,A,B,B,B,C,G,G,G,G,G,G,G,G,G,G,G)] the compressed version is [A3B3C1G11]

    Unfortunately, Nathan also needs to pack his floral suit and to comb his beard – two homeric jobs – and he is out of time to compress the notes. Help him to not embarrass himself by writing a program that can solve this task

    Input

    Each input consist of a single line, a sequence of caracteres S such as |S| ≤ 105, formed only by the letters A, B, C, D, E, F and G.

    Output

    For each input, print in a single line, such as each sequence of similar notes are replaced by the note that occurs and how many times it occurs, as showed in the example.

    Examples

    Input
    ABBGA
    Output
    A1B2G1A1
    Input
    AAABBBCGGGGGGGGGGG
    Output
    A3B3C1G11
     1 #include <stdio.h>
     2 #include <math.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 
     6 int main()
     7 {
     8     char a[100001];
     9     int m,i,j;
    10     gets(a);
    11     m=strlen(a);
    12     int k;
    13     i=0;
    14     while(i<m)
    15     {
    16         k=1;
    17         j=i+1;
    18         while(j<m)
    19         {
    20             if(a[i]==a[j])
    21             {
    22                 k++;
    23                 j++;
    24             }
    25             else
    26                 break;
    27         }
    28         printf("%c%d",a[i],k);
    29         i=j;
    30     }
    31     return 0;
    32 }
  • 相关阅读:
    APIO2020 粉刷墙壁
    上传文件超过1MB时,前端直接返回500,没有进入到上传方法
    mybatis xml 文件中 判断条件为时间,则不能做空字符串判断,否则会报错
    springcloud 多模块自动化部署 (Cloud Toolkit)
    @RequestBody Content type 'multipart/form-data;boundary=----WebKitFormBoundarybEyHr0FZTTOHW7Vq;charset=UTF-8' not supported
    读取视频时长
    zuul中使用Configuration注解后,过滤器无响应
    IDEA 2020.1 无法点击表名链接到数据源
    IDEA 常用插件
    转账到支付宝账户
  • 原文地址:https://www.cnblogs.com/xiaolitongxueyaoshangjin/p/12861281.html
Copyright © 2011-2022 走看看