2019拼多多暑期实习生机试题-01(java)

 

2019拼多多暑期实习生机试题-01(java)_第1张图片

分析:

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

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);
        }
    }

}

 

你可能感兴趣的:(编程题)