标签:学分 uri 问题: out 情况下 sys rgs 初始 href
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1202
题目不难,注意一些细节问题:
/*
* 用while循环
* 学分和成绩数据是浮点数
*/
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
double x,y;
double suma = 0.0,sumb = 0.0;
while (n-- > 0) {
x = scanner.nextDouble();
y = scanner.nextDouble();
if (y == -1.0)
continue;
suma += x;
sumb = sumb + x * dian(y);
}
if (suma == 0.0) {
System.out.println(-1);
} else {
double ans = sumb / suma;
System.out.printf("%.2f", ans);
System.out.println();
}
}
}
public static int dian(double y) {
if (y >= 90.0)
return 4;
else if (y >= 80.0)
return 3;
else if (y >= 70.0)
return 2;
else if (y >= 60.0)
return 1;
else
return 0;
}
}
[HDU 1202] The calculation of GPA
标签:学分 uri 问题: out 情况下 sys rgs 初始 href
原文地址:https://www.cnblogs.com/youpeng/p/10545723.html