有谁知道全国计算机二级C语言考试最后一题编程题如果没有运行会给分吗希望有一样经历的朋友解答
答案:2 悬赏:70 手机版
解决时间 2021-03-05 19:46
- 提问者网友:鐵馬踏冰河
- 2021-03-05 04:19
有谁知道全国计算机二级C语言考试最后一题编程题如果没有运行会给分吗希望有一样经历的朋友解答希望大家解答,麻烦了各位
最佳答案
- 五星知识达人网友:渊鱼
- 2021-03-05 05:14
import java.util.*;
public class Test {
public static void main(String[] args) {
String str = "aaaaaaaaaaaaaaaaabaadddccefqdffbaeba";
Set sets = new HashSet();
Map map = new HashMap();
for (Character c : str.toCharArray()) {
int i = 1;
if (!sets.add(c)) {
i = map.get(c);
i++;
}
map.put(c, i);
}
List> orderList = new ArrayList>(
map.entrySet());
Collections.sort(orderList,
new Comparator>() {
public int compare(Map.Entry o1,
Map.Entry o2) {
return (o1.getValue() - o2.getValue());
}
});//重写排序方法
String result="";
for (Map.Entry entry: orderList) {
result+=entry.getKey()+":"+entry.getValue()+",";
}
if(result.length()>0)
result=result.substring(0, result.length()-1);
System.out.println(result);
}
}
public class Test {
public static void main(String[] args) {
String str = "aaaaaaaaaaaaaaaaabaadddccefqdffbaeba";
Set
Map
for (Character c : str.toCharArray()) {
int i = 1;
if (!sets.add(c)) {
i = map.get(c);
i++;
}
map.put(c, i);
}
List
map.entrySet());
Collections.sort(orderList,
new Comparator
public int compare(Map.Entry
Map.Entry
return (o1.getValue() - o2.getValue());
}
});//重写排序方法
String result="";
for (Map.Entry
result+=entry.getKey()+":"+entry.getValue()+",";
}
if(result.length()>0)
result=result.substring(0, result.length()-1);
System.out.println(result);
}
}
全部回答
- 1楼网友:神的生死簿
- 2021-03-05 06:07
vf
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯