2019拼多多暑期实习生机试题-01(java)
发布日期:2021-06-20 05:37:07 浏览次数:4 分类:技术文章

本文共 704 字,大约阅读时间需要 2 分钟。

 

分析:

        直接排序,大的*小的就好。

import java.util.*;/** * @author: Mr.Hu * @create: 2019-03-01 21:10 */public class Main{    public static void main(String[] args) {        Scanner sc =new Scanner(System.in);        while (sc.hasNextInt()){            int n=sc.nextInt(),result=0;            int a[]=new int[n];            int b[] =new int[n];            for (int i = 0; i < n; i++) {                a[i]=sc.nextInt();            }            for (int i = 0; i < n; i++) {                b[i]=sc.nextInt();            }            Arrays.sort(a);            Arrays.sort(b);            for (int i = 0; i < n; i++) {                result+=a[i]*b[n-1-i];            }            System.out.println(result);        }    }}

 

转载地址:https://blog.csdn.net/h2453532874/article/details/88384619 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:2019拼多多暑期实习生机试题-02趣味字母卡片(java)
下一篇:java 取模与取余的区别

发表评论

最新留言

不错!
[***.144.177.141]2024年03月27日 19时49分29秒