Huawei OD Computer Test-Character Statistics (C++ & Java & JS & Python)

describe

Enter a string containing only lowercase English letters and numbers, and output the statistical results according to the number of different characters in descending order. If the counted numbers are the same, the results will be output in ascending order of ASCII codes.

Data range: The string length satisfies 1≤���(���)≤1000 1≤len(str)≤1000 

Enter description:

A string containing only lowercase English letters and numbers.

Output description:

A string representing the descending order of the number of occurrences of different letters. If the number of occurrences is the same, it will be output in ascending order of ASCII codes.

Example 1

enter:

aaddccdc

Output:

cda

illustrate:

In the example, c and d appear 3 times, and a appears 2 times, but the ASCII code of c is smaller than d, so c is output first, then d, and finally a.

Java:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
    public static void main(String[] args)
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str;
        try{
            while((str=br.readLine())!=null)
            {
                System.out.println(c

Guess you like

Origin blog.csdn.net/m0_68036862/article/details/132895871