首页 > 代码库 > HustOJ - 1027

HustOJ - 1027

技术分享
 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 int main()
 5 {
 6     int n, i, f, j;
 7     string s;
 8     char t;
 9 
10     cin >> n;
11 
12     for(i = 1; i <= n; i++)
13     {
14         cin >> s;
15         t = s[0];
16         f = 0;
17         for(j = 0; j < s.size(); j++)
18         {
19             if(t == s[j] && j != (s.size() - 1)) f = f + 1;
20             else if(t == s[j] && j == (s.size() - 1))
21             {
22                 f++;
23                 cout << f << t << endl;
24             }
25             else if(t != s[j] && j != (s.size() - 1))
26             {
27                 cout << f << t;
28                 t = s[j];
29                 f = 1;
30             }
31             else if(t != s[j] && j == (s.size() - 1))
32             {
33                 cout << f << t;
34                 t = s[j];
35                 f = 1;
36                 cout << f << t << endl;
37             }
38         }
39     }
40     return 0;
41 }
1027 Look and Say

注释乱码系列之二

ZOJ:2886

HustOJ - 1027