杭电1020

可以在string 后直接追加标识符  另外是数组

#include<iostream>
#include<string>
using namespace std;    
int main(){
    int n;
    cin>>n;
    string str;
    while(n--){
        int c[10000]={};
        int record[10000]={};
        int a=0,b=0,flag=0;
        cin>>str;
        str.push_back('#');  //结束标志
        while(str[a]!='#'){
            b=a+1;
            while(str[a]==str[b]){
                c[flag]++;    //记录有多少个字符串相连
                b++;
            }
            record[flag]=b-1;   //记录该字符串的位置
            a=b;
            flag++;
        }
        for(int i=0;i<flag;i++){
            if(c[i]==0)
                cout<<str[record[i]];
            else{
                cout<<c[i]+1;
                cout<<str[record[i]];
            }
                        
        }
           cout<<endl;    
    }
    
    

    return 0;
}
View Code

 

posted @ 2015-03-26 19:49  咸咸的告别  阅读(143)  评论(0编辑  收藏  举报