题面
核心思想
-
折扣价不能大于原价
-
原价才能参与满家
-
原价、折扣价和满减的价格都必须是正实数
-
格式化输出
代码
import java.util.*;
public class Main {
public static void main(String[] args) {
final long MOD = (long) (1e9 + 7);
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
boolean flag = true;
double sum = 0;
double cur = 0;
while(n-- > 0){
double a = scanner.nextDouble();
double b = scanner.nextDouble();
if(b > a || a <= 0 || b <= 0){
flag = false;
}
sum = sum + a;
cur = cur + b;
}
double a = scanner.nextDouble();
double b = scanner.nextDouble();
if(b > a || a <= 0 || b <= 0)
flag = false;
if(flag){
if(sum > a)
sum -= b;
cur = Math.min(cur, sum);
System.out.printf("%.2f\n", cur);
}
if(!flag)
System.out.println("error");
}
}
标签:cur,真题,原价,double,sum,届秋招,System,外卖,scanner
From: https://www.cnblogs.com/ganyq/p/18110427