【100 points】【Character statistics and rearrangement】

topic description

【Character statistics and rearrangement】

Given a string containing only letters, without spaces, count the number of occurrences of each letter (case-sensitive) in the string,
and in descending order of the number of occurrences of the letters. Print each letter and its occurrence count.
If the number of times is the same, sort according to the natural order, and the lowercase letters are before the uppercase letters.

Enter a description:

Enter a line, a string containing only letters.

Output description:

  • Output each letter and the number of letters in order of the number of occurrences of letters from large to small, separated by English semicolons, pay attention to the semicolon at the end;
  • Letters and times are separated by colons.

train of thought

The idea is as follows:

  1. First, we need to get the input string. You can use input()the function to take the string entered by the user and store it in a variable s.

  2. Next, we need to define the entry function of the algorithm get_result(), which is used to process and analyze the input string.

  3. existget_

Guess you like

Origin blog.csdn.net/weixin_54707168/article/details/131992456