1020

 

1 /*Problem Description
2 Given a string containing only 'A' - 'Z', we could encode it using the following method:
3
4 1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.
5
6 2. If the length of the sub-string is 1, '1' should be ignored.
7
8
9
10 Input
11 The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000.
12
13
14
15 Output
16 For each test case, output the encoded string in a line.
17
18
19
20 Sample Input
21 2
22 ABC
23 ABBCCC
24
25
26 Sample Output
27 ABC
28 A2B3C
29
30
31 Author
32 ZHANG Zheng
33  */
34  /*Description: to
35 *
36 * Author: Vincent
37 *
38 * Date:2010/04/
39 * Contact:agilely@126.com
40 * Zju CS Lab
41 */
42 //1020字符编码 统计重复字符插到其前
43 #include<iostream>
44 #include<string>
45 using namespace std;
46 int main()
47 {
48 int N,i,j,count=1;
49 char p;
50 cin>>N;
51 string *a=new string[N];
52 for(i=0;i<N;i++)
53 {
54 cin>>a[i];
55 int length=a[i].size();
56 a[i][a[i].size()]='q';
57 for(j=0;j<length;j++)
58 {
59 p=a[i][j];
60 if(a[i][j]==a[i][j+1])
61 {
62 count++;
63 p=a[i][j];
64 continue;
65 }
66 if(count==1)cout<<p;
67 else
68 {
69 cout<<count<<p;
70 count=1;
71 }
72 }
73 cout<<endl;
74 }
75 return 0;
76 }
77

 

posted @ 2010-04-15 23:16  にんじゃ  阅读(167)  评论(0)    收藏  举报