1065: 贝贝的加密工作

#include<iostream>
#include<string>
using namespace std;

int main(){
    string a,s ;
    char s1[1000];
    cin>>a;
    int i= 0,j=0;
    bool f=false;
    while(1)
    {
        f=false;
        while(a[i] !=a[i+1] && a[i + 1] !=0 && a[i] >='a' && a[i]<='z' ) 
        {
            i++;
        }
        j = i;
        while(a[i] ==a[i+1] && a[i+1] !=0 && a[i] >='a' && a[i]<='z' ) 
        {
            i++;
            f=true;
        }
        if(f == false)
            break;
            
        if(i < a.length())
            s.append(a.substr(i+1));
            
        string str1(1,a[i]-32);
        s.append( str1 );
        
        sprintf(s1,"%d",i-j+1);
        string str2(s1);
        s.append( str2 );
        
        
        if(j > 0)
            s.append(a.substr(0,j));
                
        a=s;
        s = "";
        //cout<<i<< " "<<j<<endl; 
        //cout<<a<<endl; 
        //cin.get(); 
        i= 0,j=0;
    }
    cout<<a<<endl; 
    
    return 0;
}
原文地址:https://www.cnblogs.com/shiningrise/p/6634411.html