K - MaratonIME goes to the karaoke

本文介绍了一个音乐字符串压缩问题,目标是将重复出现的音符序列压缩为音符及其重复次数。通过一个简单的C++程序实现了该功能,有效地解决了主角Nathan在卡拉OK前准备巴西经典歌曲乐谱时遇到的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

♬ 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
#include <iostream>
#include<stdio.h>
#include<string.h>
#define N 100010
using namespace std;

int main()
{
    char s[N];
    scanf("%s",s);
    int len=strlen(s);
    int i;int sum=1;
    for(i=0; i<len; i++)
        {
            if(s[i]==s[i+1])
            {
                sum++;
            }
            else
            {
                printf("%c%d",s[i],sum);
                sum=1;
            }
        }


    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值