#P0017. 字符串压缩
字符串压缩
1. 问题描述
Compression is very important in Computer & Internet applications. In this problem, we'll implement a very basic way of string compression: count consecutive repeats of a character
For exmaple,
Original string: "aabcccccaaa"
Compressed string: "a2b1c5a3"
The number after the character stands for the number of consecutive repeats.
Notice:
- If the length of compressed string is longer than original string, output the original string.
- You can use
len()method to compute string length
When will the program output original string? Can you find the math that represents the rule?
2. Input & Output
Input:
- A string
- Use
input()as input
Output:
- A string
- Use
print()for your output
Example
# Input:
aabcccccaaa
# Output:
a2b1c5a3
# Input:
dbcda
# Output:
dbcda