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;
}

 

posted @ 2017-03-28 14:12  shiningrise  阅读(527)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css