Fourth special exercise machine translation

Xiao Ming's work is a special translation of a string of English characters:
When the continuous and lowercase letters are the same, shall be replaced by the
uppercase letters, followed behind the small capital letters
to write the letters of consecutive number; At the same time, even the
character string left bit continuous exchange lowercase string and right
opposing; this operation is repeated until no consecutive identical small
letters so far. Now Xiao Ming would like to invite you to help him accomplish this special
special translation.
Input string consisting of a series of lowercase letters. (String
length is not greater than 250)
Sample an input: dilhhhhope
sample an output: opeH4dil
Sample two inputs: lodnkmgggggggoplerre
Sample two outputs: eG7lodnkmR2ople

#include<iostream>
#include<cstring>
using namespace std;
struct Word
{
    char str[255];
}phrase[300]; 
int Calculate(int number)
{
    int sum__=0;
    while(number)
    {
        sum__++;
        number/=10;
    }
    return sum__;
}
int main()
{
    char words[255]={'\0'};
    cin >> words;
    int start,sum_,final,i,j,sum=0;//sum用于判定 
    //for(i=0;i<300;i++)
        //phrase[i].str={'\0'};
    strcpy(phrase[0].str,words);//赋值 
    int length=strlen(words),how;
    char recorder;
    while(1)
    {
        i=0;
        sum_=0;
        start=0;
        final=0;
        while(phrase[sum].str[i]!='\0')
        {
            if(phrase[sum].str[i]==phrase[sum].str[i+1]&&phrase[sum].str[i]>='A')//出现重复字符 
            {
                final=start=i;//初始赋值 
                recorder=phrase[sum].str[i]-'a'+'A';//记录字符 
                while(1)
                {
                    if(phrase[sum].str[final]==phrase[sum].str[final+1])final++;
                    else break;
                }
                break;//执行交换字符串操作; 
            }
            i++;
        }
        sum_=final-start;
        if(!sum_)break;
        else//开始交换字符串;
        {
            sum_++;//统计数量 
            j=final+1;
            i=0;
            while(phrase[sum].str[j]!='\0')//将后面部分赋值给 
            {
                phrase[sum+1].str[i]=phrase[sum].str[j];
                i++;j++;
            }
            phrase[sum+1].str[i]=recorder;
            how=Calculate(sum_);//处理数字出现类型 
            if(how==1)
            {
                phrase[sum+1].str[i+1]=sum_+'0';//数字大小得分类讨论 
                i+=2;
            }
            else if(how==2)
            {
                phrase[sum+1].str[i+1]=sum_/10%10+'0';
                phrase[sum+1].str[i+2]=sum_%10+'0';
                i+=3;
            }
            else
            {
                phrase[sum+1].str[i+1]=sum_/100%10+'0';
                phrase[sum+1].str[i+2]=sum_/10%10+'0';
                phrase[sum+1].str[i+3]=sum_%10+'0';
                i+=4;
            }
            j=0;
            while(j!=start)
            {
                phrase[sum+1].str[i]=phrase[sum].str[j];
                i++;j++;
            }
        }
        sum++; 
    }
    cout << phrase[sum].str;
    return 0;
}

This question is intended to clear title which requires the repeated transfer alphabet
letters plus the number indicates the number of repeats;

ignored considering the value of 40 obtained only sum_ initial design
where the input is sample z <repeat 26 times>
occurs clues repeated by the letters not digital,
this is because I sum _ + '0' converted form with
since the character space constraints, it is not directly above 9
directly converted digital, so the use Calculator
calculates the size; of course, present problems limiting the scope 250 when
this occurs over the length of life of the enemyRun over
time

<Font face = "Arial" size = 4 just feels kinda interesting question quite like mirror-reversed

Guess you like

Origin www.cnblogs.com/pekkasuper/p/12507950.html