- 时间限制:1秒空间限制:32768K
- 算法知识视频讲解
题目描述
实现删除字符串中出现次数最少的字符,若多个字符出现次数一样,则都删除。输出删除这些单词后的字符串,字符串中其它字符保持原来的顺序。
输入描述:
字符串只包含小写英文字母, 不考虑非法输入,输入的字符串长度小于等于20个字节。
输出描述:
删除字符串中出现次数最少的字符后的字符串。
输入例子:
abcdd
输出例子:
dd
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {int min = 21;int[] a = new int[11000];String s = sc.nextLine();for (int i = 0; i < s.length(); i++) {int x = s.charAt(i);a[x]++;}for (int i = 0; i < s.length(); i++) {int x = s.charAt(i);if (a[x] < min) {min = a[x];}}for (int i = 0; i < s.length(); i++) {int x = s.charAt(i);if (a[x] != min) {System.out.print(s.charAt(i));}}System.out.println();}}
}