31: String p-encoding, 31 string p-Encoding

Source: Internet
Author: User

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 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.