首页 > 其他 > 详细

杭电1020

时间:2015-03-26 22:21:08      阅读:190      评论:0      收藏:0      [点我收藏+]

可以在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

 

杭电1020

原文:http://www.cnblogs.com/wintersong/p/4369857.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!