| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
 买学问 - 大牛一对一辅导，有问必答 买学问 - 专业的付费知识问答平台

已结贴   问题点数：20  回复次数：3

1：试写一个算法，由大至小依次输出顺序读入的三个整数值。
2：假设三个班参加学校运动会，项目共有四项，试编写算法，统计各班男女总分和团体总分。
3：设线性表存于a (1:  arrsize)的前elenum个分量中，且递增有序。试编写算法，用数组和链表分别实现将x插入到线性表的适当位置上，以保持线性表的有序性
得分:20

得分:0

```import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.swing.JOptionPane;

public class Test {
public static void main(String[] args) {
String inputStr = null;
List<Integer> list = new ArrayList<>();
try {
for(int i=1; i<=3; i++) {
inputStr = JOptionPane.showInputDialog("请输入第"+i+"整数");
int val = Integer.parseInt(inputStr);
}
} catch (NumberFormatException e) {
System.out.println("[error]"+e.getMessage());
return;
}
list.sort(Collections.reverseOrder());
System.out.println(list);
}
}```

得分:0

```package com.huawei.day25;

import java.util.HashMap;
import java.util.Map;

public class Test {
private static final String ITEM_A = "item-a";
private static final String ITEM_B = "item-b";
private static final String ITEM_C = "item-c";
private static final String ITEM_D = "item-d";
//
private static final String CLASS_KEY = "className";
private static final String CLASS_A = "class-a";
private static final String CLASS_B = "class-b";
private static final String CLASS_C = "class-c";
//
private static final String GENDER_KEY = "gender";
private static final String FEMALE = "female";
private static final String MALE = "male";
public static void main(String[] args) {
// stuId,items
Map<Integer, Map<String, Integer>> scoreMap = new HashMap<>();
// stuId,info
Map<Integer, Map<String, String>> infoMap = new HashMap<>();
//
Map<String, Integer> score = new HashMap<>();
score.put(ITEM_A, 1);
score.put(ITEM_B, 2);
score.put(ITEM_C, 3);
score.put(ITEM_D, 4);
scoreMap.put(1, score);
scoreMap.put(2, score);
scoreMap.put(3, score);
//
Map<String, String> info = new HashMap<>();
info.put(CLASS_KEY, CLASS_A);
info.put(GENDER_KEY, FEMALE);
infoMap.put(1, info);
info = new HashMap<>();
info.put(CLASS_KEY, CLASS_B);
info.put(GENDER_KEY, MALE);
infoMap.put(2, info);
info = new HashMap<>();
info.put(CLASS_KEY, CLASS_C);
info.put(GENDER_KEY, FEMALE);
infoMap.put(3, info);
System.out.println(scoreMap);
System.out.println(infoMap);
// analysis result
// class,score
Map<String, Integer> classMap = new HashMap<>();
// class,gender,score
Map<String, Map<String,Integer>> stuMap = new HashMap<>();
for(int stuId : scoreMap.keySet()) {
Map<String, Integer> entry = scoreMap.get(stuId);
String className = infoMap.get(stuId).get(CLASS_KEY);
String gender = infoMap.get(stuId).get(GENDER_KEY);
for(String itemName : entry.keySet()) {
if(stuMap.get(className) == null) {
stuMap.put(className, new HashMap<>());
}
if(classMap.get(className) == null) {
classMap.put(className, 0);
}
if(stuMap.get(className).get(gender)==null) {
stuMap.get(className).put(gender, 0);
}
int tmpScore = stuMap.get(className).get(gender);
stuMap.get(className).put(gender, tmpScore + entry.get(itemName));
classMap.put(className, tmpScore + entry.get(itemName));
}
}
System.out.println(classMap);
System.out.println(stuMap);
}
}

```

{1={item-d=4, item-c=3, item-b=2, item-a=1}, 2={item-d=4, item-c=3, item-b=2, item-a=1}, 3={item-d=4, item-c=3, item-b=2, item-a=1}}
{1={gender=female, className=class-a}, 2={gender=male, className=class-b}, 3={gender=female, className=class-c}}
{class-b=10, class-a=10, class-c=10}
{class-b={male=10}, class-a={female=10}, class-c={female=10}}

[此贴子已经被作者于2018-10-22 08:13编辑过]

• 4
• 1/1页
• 1