标题:大神们帮帮忙写写程序喽
只看楼主
语言迷弟
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-10-21
结帖率:0
已结贴  问题点数:20 回复次数:3 
大神们帮帮忙写写程序喽
1:试写一个算法,由大至小依次输出顺序读入的三个整数值。
2:假设三个班参加学校运动会,项目共有四项,试编写算法,统计各班男女总分和团体总分。
3:设线性表存于a (1:  arrsize)的前elenum个分量中,且递增有序。试编写算法,用数组和链表分别实现将x插入到线性表的适当位置上,以保持线性表的有序性
搜索更多相关主题的帖子: 算法 编写 总分 线性表 有序 
2018-10-21 17:38
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2276
专家分:10647
注 册:2015-3-19
得分:20 
作业?

剑栈风樯各苦辛,别时冰雪到时春
2018-10-21 22:08
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2276
专家分:10647
注 册:2015-3-19
得分: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);
                list.add(val);
            }
        } catch (NumberFormatException e) {
            System.out.println("[error]"+e.getMessage());
            return;
        }
        list.sort(Collections.reverseOrder());
        System.out.println(list);
    }
}

剑栈风樯各苦辛,别时冰雪到时春
2018-10-21 22:23
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2276
专家分:10647
注 册:2015-3-19
得分: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编辑过]


剑栈风樯各苦辛,别时冰雪到时春
2018-10-21 23:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-490569-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027499 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved