31: String p-encoding, 31 string p-Encoding
31: String p-Encoding
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Given a number character ('0', '1', '2 ',..., '9'). Write the p-encoded string of str. For example, string 122344111 can be described as "1 1, 2 2, 1 3, 2 4, 3 1 ", therefore, we say that the 122344111 p-type encoding string is 1122132431. Similarly, the encoding string 101 can be used to describe 1111111111; 00000000000 can be described as "11 0 ", therefore, its p-type encoding string is 110; 100200300 can be described as "1, 2 0, 1 2, 2 0, 1 3, 2 0", so its p-type encoding string is 112012201320.
-
Input
-
Enter only one line, including the string str. Each line of string can contain a maximum of 1000 numeric characters.
-
Output
-
Output the p-encoded string corresponding to this string.
-
Sample Input
-
122344111
-
Sample output
-
1122132431
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 using namespace std; 6 char a[10001]; 7 int tot=1; 8 int main() 9 {10 gets(a);11 int l=strlen(a);12 for(int i=0;i<l;i++)13 {14 if(a[i]==a[i+1])15 {16 tot++;17 }18 else19 {20 cout<<tot<<a[i];21 tot=1; 22 }23 }24 return 0;25 }