解题思路:
注意事项:
参考代码:
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int i = 0;
String str;
int max=0;
Map<String, Integer> map = new LinkedHashMap<String, Integer>();
while(scanner.hasNext()) {
str=scanner.nextLine();
str=str.toUpperCase();
String[] a=str.split("\\W+");
for(i=0;i<a.length;i++) {
if(a[i].lastIndexOf(".")!=-1)
a[i]=a[i].substring(0, a[i].lastIndexOf("."));
//System.out.println(a[i]);
if(map.get(a[i])==null)
map.put(a[i],1);
else
map.put(a[i], map.get(a[i])+1);
max=Math.max(max, a[i].length());
}
for(String key:map.keySet()) {
System.out.printf("%"+max+"s:", key);
for(i=0;i<map.get(key);i++)
System.out.print("*");
System.out.println(map.get(key));
}
}
}
}
0.0分
0 人评分