第一行 总的课程数n(n<10); 第二行 相应课程的学分(两个学分间用空格隔开); 第三行 对应课程的实际得分; 此处输入的所有数字均为整数。
输出有一行,总评绩点,精确到小数点后2位小数。(printf("%.2f",GPA);)
5 4 3 4 2 3 91 88 72 69 56
2.52
#include<iostream> #include<cstdio> using namespace std; const int maxn = 11; int num[maxn]; // 学分 // 将分数换成 GPA double tgpa(int n) { if(n >= 90 && n <= 100) { return 4.0; } else if(n >= 85 && n <= 89) { return 3.7; } else if(n >= 82 && n <= 84) { return 3.3; } else if(n >= 78 && n <= 81) { return 3.0; } else if(n >= 75 && n <= 77) { return 2.7; } else if(n >= 72 && n <= 74) { return 2.3; } else if(n >= 68 && n <= 71) { return 2.0; } else if(n >= 64 && n <= 67) { return 1.5; } else if(n >= 60 && n <= 63) { return 1.0; } else { return 0.0; } } int main() { int n; double GPA; // 平均GPA int total; // 总学分 int score; // 成绩 while(cin >> n) { GPA = 0; total = 0; // input for(int i = 0; i < n; ++i) { cin >> num[i]; total += num[i]; } for(int i = 0; i < n; ++i) { cin >> score; GPA += num[i]*tgpa(score); } // end input printf("%.2lf\n", GPA / total); } return 0; }
#include<vector> #include<stdio.h> using namespace std; double getGPA(int n){ if(n>=90) return 4.0; else if(n>=85&&n<=89) return 3.7; else if(n>=82&&n<=84) return 3.3; else if(n>=78&&n<=81) return 3.0; else if(n>=75&&n<=77) return 2.7; else if(n>=71&&n<=74) return 2.3; else if(n>=68&&n<=71) return 2.0; else if(n>=60&&n<=63) return 1.0; else return 0; } int main(){ int n; scanf("%d",&n); vector<int> credit(n,0); vector<int> score(n,0); vector<double> gpas(n,0); int totalScore=0; for(int i=0;i<n;i++){ scanf("%d",&credit[i]); totalScore+=credit[i]; } for(int i=0;i<n;i++){ scanf("%d",&score[i]); gpas[i]=getGPA(score[i]); } double totalGpas=0; for(int i=0;i<n;i++){ totalGpas+=gpas[i]*credit[i]; } printf("%.2f\n",totalGpas/totalScore); return 0; }
#include <iostream> #include <map> using namespace std; int main() { map<int, float, greater<int>> s{ {90,4.0},{85,3.7},{82,3.3},{78,3.0},{75,2.7}, {72,2.3},{68,2.0},{64,1.5},{60,1.0},{00,0.0} }; int n, i, a[20], tmp; while (cin >> n) { float GPA = 0, sum = 0; for (i = 0; i < n * 2; ++i) cin >> a[i]; for (i = 0; i < n; ++i) { sum += a[i]; GPA += a[i] * s.lower_bound(a[i + n])->second; } printf("%.2f\n", GPA / sum); } return 0; }
#include<stdio.h> struct chengji{ float score; float jidian; float xuefen; }a[10]; int main() { int n,i;float sum1=0,sum2=0; scanf("%d",&n); for(i=0;i<n;i++) scanf("%f",&a[i].xuefen); for(i=0;i<n;i++) scanf("%f",&a[i].score); //1.计算绩点 for(i=0;i<n;i++) { if(a[i].score>=90&&a[i].score<=100) a[i].jidian=4.0; if(a[i].score>=85&&a[i].score<=89) a[i].jidian=3.7; if(a[i].score>=82&&a[i].score<=84) a[i].jidian=3.3; if(a[i].score>=78&&a[i].score<=81) a[i].jidian=3.0; if(a[i].score>=75&&a[i].score<=77) a[i].jidian=2.7; if(a[i].score>=72&&a[i].score<=74) a[i].jidian=2.3; if(a[i].score>=68&&a[i].score<=71) a[i].jidian=2.0; if(a[i].score>=64&&a[i].score<=67) a[i].jidian=1.5; if(a[i].score>=60&&a[i].score<=63) a[i].jidian=1.0; if(a[i].score<=59) a[i].jidian=0; } for(i=0;i<n;i++) {sum1+=a[i].jidian*a[i].xuefen;sum2+=a[i].xuefen;} float GPA=sum1/sum2; printf("%.2f",GPA); }
//博客链接:https://blog.csdn.net/qq_44840148/article/details/104630377 import java.util.Scanner; public class Main1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNextInt()){ int n=sc.nextInt(); //输入总共有多少门课程 int[] gradeCredit=new int[n];//存储每门课学分的数组 int[] grade=new int[n];//存储每门课分数的数组 for(int i=0;i<n;i++){ gradeCredit[i]=sc.nextInt(); //读入输入的第二行 } for(int i=0;i<n;i++){ grade[i]=sc.nextInt();//读入输入的第三行 } System.out.printf("%.2f",averageCredit(gradeCredit,grade)); } } public static double averageCredit(int[] gradeCredit,int[] grade){ double sum=0.0;//表示所有课程加起来应得的学分和 double allClassCredit=0.0; //表示该学生能实际得到的学分绩点 for(int i=0;i<grade.length;i++){ allClassCredit+=gradeCredit[i]*GPA(grade[i]); sum+=gradeCredit[i]; } return allClassCredit/sum; } //求每门课的成绩对应的学分绩点 public static double GPA(int grade){ double gpa = 0.0; if(grade>=90&&grade<=100) gpa=4.0; if(grade>=85&&grade<=89) gpa=3.7; if(grade>=82&&grade<=84) gpa=3.3; if(grade>=78&&grade<=81) gpa=3.0; if(grade>=75&&grade<=77) gpa=2.7; if(grade>=72&&grade<=74) gpa=2.3; if(grade>=68&&grade<=71) gpa=2.0; if(grade>=64&&grade<=67) gpa=1.5; if(grade>=60&&grade<=63) gpa=1.0; if(grade<60) gpa=0.0; return gpa; } }
#include<bits/stdc++.h> int main(){ int n,a[10]={0}; float b[10]={0},gpa=0,s=0; while(scanf("%d",&n)!=EOF){ for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++){ scanf("%f",&b[i]); if(b[i]>=90 && b[i]<=100) b[i]=4.0; else if(b[i]>=85 && b[i]<=89) b[i]=3.7; else if(b[i]>=82 && b[i]<=84) b[i]=3.3; else if(b[i]>=78 && b[i]<=81) b[i]=3.0; else if(b[i]>=75 && b[i]<=77) b[i]=2.7; else if(b[i]>=72 && b[i]<=74) b[i]=2.3; else if(b[i]>=68 && b[i]<=71) b[i]=2.0; else if(b[i]>=64 && b[i]<=67) b[i]=1.5; else if(b[i]>=60 && b[i]<=63) b[i]=1.0; else b[i]=0; } for(int i=0;i<n;i++){ gpa=gpa+a[i]*b[i]; s=s+a[i]; } printf("%.2f\n",gpa/s); } }
#include<iostream> #include<iomanip> using namespace std; int main() { int n; cin >> n; int* credit = new int[n]; int* grade = new int[n]; for (int i = 0; i<n; i++) cin >> credit[i]; for (int i = 0; i < n; i++) cin >> grade[i]; double gpa = 0; for (int i = 0; i<n; i++) { if (grade[i] >= 90 && grade[i] <= 100) gpa += 4.0*credit[i]; else if (grade[i] >= 85 && grade[i] <= 89) gpa += 3.7*credit[i]; else if (grade[i] >= 82 && grade[i] <= 84) gpa += 3.3*credit[i]; else if (grade[i] >= 78 && grade[i] <= 81) gpa += 3.0*credit[i]; else if (grade[i] >= 75 && grade[i] <= 77) gpa += 2.7*credit[i]; else if (grade[i] >= 72 && grade[i] <= 74) gpa += 2.3*credit[i]; else if (grade[i] >= 68 && grade[i] <= 71) gpa += 2.0*credit[i]; else if (grade[i] >= 64 && grade[i] <= 67) gpa += 1.5*credit[i]; else if (grade[i] >= 60 && grade[i] <= 63) gpa += 1.0*credit[i]; else gpa += 0; } int totalCredit = 0; for (int i = 0; i<n; i++) { totalCredit += credit[i]; } cout << fixed << setprecision(2) << gpa / totalCredit << endl; }
while True: try: num = int(input()) credits = list(map(int,input().split())) scores = list(map(int,input().split())) grades = 0 for i in range(num): if 100 >= scores[i] >= 90: grades += 4.0*credits[i] elif scores[i] >= 85: grades += 3.7*credits[i] elif scores[i] >= 82: grades += 3.3*credits[i] elif scores[i] >= 78: grades += 3.0*credits[i] elif scores[i] >= 75: grades += 2.7*credits[i] elif scores[i] >= 72: grades += 2.3*credits[i] elif scores[i] >= 68: grades += 2.0*credits[i] elif scores[i] >= 64: grades += 1.5*credits[i] elif scores[i] >= 60: grades += 1.0*credits[i] print("%.2f"%(grades/sum(credits))) except Exception: break
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int gradePoint[]=new int[n];//每门课学分 int coursePoint[]=new int[n];//每门课分数 for(int i=0;i<n;i++){ gradePoint[i]=in.nextInt(); } for(int i=0;i<n;i++){ coursePoint[i]=in.nextInt(); } in.close(); System.out.printf("%.2f",gradePointAverage(gradePoint,coursePoint));//格式输出 } public static double pointOfEachCourse(int grade){//根据实际成绩判断学分方法 double point = 0.0; if(grade>=90&&grade<=100) point=4.0; if(grade>=85&&grade<=89) point=3.7; if(grade>=82&&grade<=84) point=3.3; if(grade>=78&&grade<=81) point=3.0; if(grade>=75&&grade<=77) point=2.7; if(grade>=72&&grade<=74) point=2.3; if(grade>=68&&grade<=71) point=2.0; if(grade>=64&&grade<=67) point=1.5; if(grade>=60&&grade<=63) point=1.0; if(grade<60) point=0.0; return (double)point; } //计算平均绩点的方法 public static double gradePointAverage(int[] gradePoint,int[] coursePoint){ double gradePointTotal=0; double gradeOfEachCourseTotal=0; for(int i=0;i<gradePoint.length;i++){ gradePointTotal+=pointOfEachCourse(coursePoint[i])*gradePoint[i]; gradeOfEachCourseTotal+=gradePoint[i]; } return (double)gradePointTotal/gradeOfEachCourseTotal; } }
a,b,c=input(),list(map(int,input().split())),list(map(int,input().split()))
total=0
for i,v in enumerate(c):
if 90<=v<=100:total+=b[i]*4
elif 85<=v<=89:total+=b[i]*3.7
elif 82<=v<=84:total+=b[i]*3.3
elif 78<=v<=81:total+=b[i]*3
elif 75<=v<=77:total+=b[i]*2.7
elif 72<=v<=74:total+=b[i]*2.3
elif 68<=v<=71:total+=b[i]*2
elif 64<=v<=67:total+=b[i]*1.5
elif 60<=v<=63:total+=b[i]*1
else:total+=b[i]*0
print("{0:.2f}".format(total/sum(b)))
d = {60:0,64:1,68:1.5,72:2,75:2.3,78:2.7,82:3,85:3.3,90:3.7,101:4} a,b,j,p = int(input()),list(map(int,input().split())),-1,0 for i in map(int,input().split()): j,k = j + 1,0 while i >= list(d)[k]: k += 1 p += d[list(d)[k]] * b[j] print('{:.2f}'.format(p / sum(b)))
import java.text.DecimalFormat; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] credit = new int[n]; int[] score = new int[n]; // 总的学分 int credits=0; for (int i = 0; i < n; i++){ credit[i]=scanner.nextInt(); credits+= credit[i]; } for (int i = 0; i < n; i++) score[i]= scanner.nextInt(); double average =0; for (int i = 0; i < n; i++) average+= scoreToGPA(score[i])*credit[i]; DecimalFormat df = new DecimalFormat(".00"); System.out.println(df.format(average/credits)); } /** * 90——100 4.0 85——89 3.7 82——84 3.3 78——81 3.0 75——77 2.7 72——74 2.3 68——71 2.0 64——67 1.5 60——63 1.0 60以下 0 * */ static double scoreToGPA(int score){ if (score>=90) return 4.0; else if (score>=85) return 3.7; else if (score>=82) return 3.3; else if (score>=78) return 3.0; else if (score>=75) return 2.7; else if (score>=72) return 2.3; else if (score>=68) return 2.0; else if (score>=64) return 1.5; else if (score>=60) return 1.0; else return 0.0; } }
/* 100 - 90 4.0 85 - 89 3.7 82 - 84 3.3 78 - 81 3.0 75 - 77 2.7 72 - 74 2.3 68 - 71 2.0 64 - 67 1.5 60 - 63 1.0 0 - 60 0 */ #include<vector> #include<iostream> using namespace std; float calCredit(int num){ if(num>=90){ return 4.0; }else if(num>=85){ return 3.7; }else if(num>=82){ return 3.3; }else if(num>=78){ return 3.0; }else if(num>=75){ return 2.7; }else if(num>=72) return 2.3; else if(num>=68){ return 2.0; }else if(num>=64){ return 1.5; }else if(num>=60){ return 1.0; }else{ return 0; } } int main(){ int N; int allCredits = 0; scanf("%d",&N); vector<int> credits; vector<int> grades; for(int i=0;i<N;i++){ int c; cin>>c; allCredits+=c; credits.push_back(c); } for(int i=0;i<N;i++){ int g; cin>>g; grades.push_back(g); } float res1 = 0; for(int i=0;i<N;i++){ float tmp = calCredit(grades[i])*credits[i]; res1+=tmp; } float GPA = res1/allCredits; printf("%.2f\n",GPA); }
#include <iomanip> #include <iostream> using namespace std; struct sub{ int xuefen; int defen; }sub[12]; int main() { int n; cin>>n; for(int i=0;i<n;i++){ cin>>sub[i].xuefen; } for(int i=0;i<n;i++){ cin>>sub[i].defen; } double jidian[12]; double xuefenjidian[12]; for(int i=0;i<n;i++){ if(sub[i].defen>=90&&sub[i].defen<=100) jidian[i]=4.0; else if(sub[i].defen>=85&&sub[i].defen<=89) jidian[i]=3.7; else if(sub[i].defen>=82&&sub[i].defen<=84) jidian[i]=3.3; else if(sub[i].defen>=78&&sub[i].defen<=81) jidian[i]=3.0; else if(sub[i].defen>=75&&sub[i].defen<=77) jidian[i]=2.7; else if(sub[i].defen>=72&&sub[i].defen<=74) jidian[i]=2.3; else if(sub[i].defen>=68&&sub[i].defen<=71) jidian[i]=2.0; else if(sub[i].defen>=64&&sub[i].defen<=67) jidian[i]=1.5; else if(sub[i].defen>=60&&sub[i].defen<=63) jidian[i]=1.0; else jidian[i]=0; } for(int i=0;i<n;i++){ xuefenjidian[i]=jidian[i]*sub[i].xuefen; } double z1=0;//总绩点 int z2=0;//总学分 for (int i=0;i<n;i++){ z1+=xuefenjidian[i]; } for(int i=0;i<n;i++){ z2+=sub[i].xuefen; } double GPA=z1/z2; cout<<fixed<<setprecision(2)<<GPA; } // 64 位输出请用 printf("%lld")
#include <iomanip> #include <ios> #include <iostream> #include <vector> using namespace std; //根据实际成绩计算绩点 double gpa(int grade) { return grade >= 90 ? 4.0 : grade >= 85 ? 3.7 : grade >= 82 ? 3.3 : grade >= 78 ? 3.0 : grade >= 75 ? 2.7 : grade >= 72 ? 2.3 : grade >= 68 ? 2.0 : grade >= 64 ? 1.5 : grade >= 60 ? 1.0 : 0; } int main() { int n; while (cin >> n) { vector<int>course_score; //每门课程的学分 int sum_score = 0; //所有课程学分总和 for (int i = 0; i < n; i++) { int score; //课程学分 cin >> score; sum_score += score; course_score.push_back(score); } double sum_gpa = 0; //所有学科绩点之和 for (int i = 0; i < n; i++) { int grade; //实际成绩 cin >> grade; sum_gpa += gpa(grade) * course_score[i]; } //输出总评绩点,精确到小数点后2位 cout << setiosflags(ios::fixed) << setprecision(2) << sum_gpa / sum_score << endl; } return 0; }
#include <cstdio> float getGradeClass(int grade){ float gradeclass; if( 90<=grade && grade<=100){ gradeclass = 4.0; }else if(85<=grade && grade<=89){ gradeclass = 3.7; }else if(82<=grade && grade<=84){ gradeclass = 3.3; }else if(78<=grade && grade<=81){ gradeclass = 3.0; }else if(75<=grade && grade<=77){ gradeclass = 2.7; }else if(72<=grade && grade<=74){ gradeclass = 2.3; }else if(68<=grade && grade<=71){ gradeclass = 2.0; }else if(64<=grade && grade<=67){ gradeclass = 1.5; }else if(60<=grade && grade<=63){ gradeclass = 1.0; }else{ gradeclass = 0; } return gradeclass; } int main(){ int n; scanf("%d",&n); int credit[10];//学分 int sum_credit = 0;//总学分 int grade[10];//单科成绩 float gradeclass[10];//成绩对应的绩点 float subjectclass[10];//学科绩点 = 成绩对应绩点*学分 float sum_subjectclass = 0;//学科绩点之和 //输入学分 for(int i = 0; i < n; ++i){ scanf("%d",&credit[i]); sum_credit += credit[i]; } //输入成绩 for(int i = 0; i < n; ++i){ scanf("%d",&grade[i]); gradeclass[i] = getGradeClass(grade[i]); subjectclass[i] = gradeclass[i]*credit[i]; sum_subjectclass += subjectclass[i]; } float GPA = sum_subjectclass/sum_credit; printf("%0.2f",GPA); return 0; }