凭记忆写的,随便看看吧 import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
char[] c = scan.next().toCharArray();
HashMap<Character,Integer> map = new HashMap<>();
for (int i = 0; i < c.length; i++) {
map.put(c[i],i);
}
int left = 0;
int right = 0;
for (int i = 0; i < c.length; i++) {
right = right > map.get(c[i]) ? right : map.get(c[i]);
if (right == c.length - 1) {
System.out.print(right - left + 1);
break;
}
if (right == i) {
System.out.print(right - left + 1 + " ");
left = i + 1;
}
}
}
}