首页 > 学院 > 开发设计 > 正文

hihocoder 139周

2019-11-06 08:05:15
字体:
来源:转载
供稿:网友

题目较简单,但是贴一下别人的代码,学到不少东西

 import java.util.Scanner;   public class Main{    class PRoduct{    double price;    int interest;    public Product(double price,int interest){        this.price = price;        this.interest = interest;    }}public void process(){    Scanner scan = new Scanner(System.in);    int testCaseAmount = scan.nextInt();    scan.nextLine();    while(testCaseAmount--!=0){        int productAmount = scan.nextInt();        scan.nextLine();        Product[] products = new Product[productAmount];        for(int i = 0; i < products.length;i++){            products[i] = new Product(scan.nextDouble(),scan.nextInt());            scan.nextLine();        }        System.out.println(func(products));    }    scan.close();}private int func(Product[] products) {    int maxInterest = 0;    for(int i = 0; i < products.length;i++){        for(int j = i+1; j < products.length;j++){            for(int k = j+1; k < products.length;k++){                double curPriceSum = products[i].price+products[j].price+products[k].price;                int temp = (int) curPriceSum;                if(temp!=curPriceSum||temp%5!=0){                    continue;                }                else{                    maxInterest = Math.max(maxInterest,products[i].interest+products[j].interest+products[k].interest);                }            }        }    }    for(int i = 0; i < products.length;i++){        for(int j = i+1; j < products.length;j++){            double curPriceSum = products[i].price+products[j].price;            int temp = (int) curPriceSum;            if(temp!=curPriceSum||temp%5!=0){                continue;            }            else{                maxInterest = Math.max(maxInterest,products[i].interest+products[j].interest);            }        }    }    for(int i = 0; i < products.length;i++){        double curPriceSum = products[i].price;        int temp = (int) curPriceSum;        if(temp!=curPriceSum||temp%5!=0){            continue;        }        else{            maxInterest = Math.max(maxInterest,products[i].interest);        }    }    return maxInterest;}public static void main(String[] args){    Main m = new Main();    m.process();}}


上一篇:对Map的排序

下一篇:instanceof运算符

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表