网站建站是 什么,免费的短视频app大全安卓,购物网站建设费用,医药公司网站建设需求: 公司老板做了一笔大生意#xff0c;想要给每位员工分配一些奖金#xff0c;想通过游戏的方式来决定每个人分多少钱。按照员工的工号顺序#xff0c;每个人随机抽取一个数字。按照工号的顺序往后排列#xff0c;遇到第一个数字比自己数字大的#xff0c;那么#xf…需求: 公司老板做了一笔大生意想要给每位员工分配一些奖金想通过游戏的方式来决定每个人分多少钱。按照员工的工号顺序每个人随机抽取一个数字。按照工号的顺序往后排列遇到第一个数字比自己数字大的那么前面的员工就可以获得“距离 * 数字差值”的奖金。如果遇不到比自己数字大的就给自己分配随机数数量的奖金。 例如按照工号顺序的随机数字是2,10,3。 第2个员工的数字10比第1个员工的数字2大所以第1个员工可以获得1 * 10-28。 第2个员工后面没有比他数字更大的员工所以他获得他分配的随机数数量的奖金就是10。 第3个员工是最后一个员工后面也没有比他更大数字的员工所以他得到的奖金是3。 请帮老板计算一下每位员工最终分到的奖金都是多少钱。 输入描述 第一行n表示员工数量包含最后一个老板 第二是每位员工分配的随机数字 输出描述 最终每位员工分到的奖金数量 输入 3 --个数 2 10 3 --随机数 输出 8 10 3 -- 结果 编码
public class TakePrize {public static void main(String[] args) {Scanner sc new Scanner(System.in);System.out.print(请输入员工数量:);int len sc.nextInt();System.out.print(随机生成员工号:);//调用方法1ListInteger list norepeat(len);System.out.println(list.toString());//调用方法2ListInteger ll show(list);System.out.println(员工分的奖金数:ll.toString());}/*** 开始遍历并查找到第一个比自己大的数那么就自己的奖金就是这个数减自己的数如果没有就自己的奖金就是本身随机数。* param list* return*/private static ListInteger show(ListInteger list) {int flag 0;ListInteger lists new ArrayList();//循环比较for (int i 0; i list.size(); i) {for (int j i1 ; j list.size(); j) {//判断前一个数是否大于后面的数if (list.get(i) list.get(j)) {Integer money (list.get(j) - list.get(i)) * (j - i);lists.add(money);flag 1;break;}}//如果没有大于后面值if (flag 0) {lists.add(list.get(i));}flag 0; //重置}return lists;}/*** 随机数字不重复员工数量(包含老板)范围1 ~ 10000** param count* return*/public static ListInteger norepeat(int count) {//随机对象Random random new Random();//set集合对象SetInteger set new HashSet();//循环while (true) {//随机数范围1 ~ 10000
// int number random.nextInt(10000) 1;int number random.nextInt(10) 1;set.add(number);//判断是否满足员工数量if (set.size() count) {break;}}//返回集合对象return new ArrayList(set);}
}效果