编程练习10

都是水题啊

 1 //连续字符统计,如aabcccd输出a2b1c3d1
 2 #include <iostream>
 3 using namespace std;
 4 #define N 100
 5 
 6 void func(char* str)
 7 {
 8     pair<char,int> pr;
 9     int i,j=0,len=strlen(str);
10     int num[N]={0};
11     char c[N]={0};
12 
13     c[0]=str[0];
14     num[0]=1;
15     for(i=1;i<len;++i)
16     {
17         if(str[i]!=str[i-1])
18         {
19             c[++j]=str[i];
20         }
21         num[j]++;
22     }
23 
24     i=0;
25     while(num[i])
26     {
27         cout<<c[i]<<num[i];
28         i++;
29     }
30 }
31 
32 int main()
33 {
34     char str[N];
35     
36     while(cin>>str)
37     {
38         if(strcmp(str,"end")!=0)
39             func(str);
40         else
41             break;
42     }
43 
44     cout<<endl;
45 
46     return 0;
47 }

 

 

posted on 2012-09-13 09:25  lyncre  阅读(127)  评论(0)    收藏  举报

导航