字符串个数

来源:互联网 发布:淘宝最新规则在哪里看 编辑:程序博客网 时间:2024/05/21 17:50

给定一个字符串,请你将字符串重新编码,将连续的字符替换成“连续
出现的个数+字符”。
比如字符串AAAABCCDAA会被编码成4A1B2C1D2A

#include<iostream>#include<string>using namespace std;int main(){    char str[10001] = {0};    cin>>str;    int count = 1;    int i = 0;    for(i=0; i<10000; i++)    {        if(str[i] == str[i+1])            count++;        else        {            cout<<count<<str[i];            if(str[i+1] !='\0')            {                count = 1;            }        }    }    if(str[i] !='\0')    {        cout<<count<<str[i];    }    return 0;}
1 0