import java.util.Scanner; public class Main{ public static double getPoint(int grade){ if(grade>=90&&grade<=100){ return 4.0; }else if(grade>=85&&grade<=89){ return 3.7; }else if(grade>=82&&grade<=84){ return 3.3; }else if(grade>=78&&grade<=81){ return 3.0; }else if(grade>=75&&grade<=77){ return 2.7; }else if(grade>=72&&grade<=74){ return 2.3; }else if(grade>=68&&grade<=71){ return 2.0; }else if(grade>=64&&grade<=67){ return 1.5; }else if(grade>=60&&grade<=63){ return 1.0; }else{ return 0.0; } } public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] score=new int[n]; for(int i=0;i<n;i++){ score[i]=sc.nextInt(); } int[] grade=new int[n]; for(int i=0;i<n;i++){ grade[i]=sc.nextInt(); } double sp=0;double gp=0; for(int i=0;i<n;i++){ gp+=getPoint(grade[i])*score[i]; sp+=score[i]; } double GPA=gp/sp; System.out.printf("%.2f",GPA); // System.out.printf("%f",gp);//67.1 // System.out.printf("%f",sp);//25 } }
这个题用C 语言写总是通不过这个示例的为什么??? 计算的总是2.52 然而用Java算出来的话就是2.68
为什么??????