第一行 总的课程数n(n<10); 第二行 相应课程的学分(两个学分间用空格隔开); 第三行 对应课程的实际得分; 此处输入的所有数字均为整数。
输出有一行,总评绩点,精确到小数点后2位小数。(printf("%.2f",GPA);)
5 4 3 4 2 3 91 88 72 69 56
2.52
/*
* @Author: Spring Breeze
* @Date: 2021-06-29 19:48:16
* @FilePath: \algorithm\test.c
* @LastEditTime: 2022-03-24 19:19:36
*/
#include <stdio.h>
#define LEVEL_1 90
#define LEVEL_2 85
#define LEVEL_3 82
#define LEVEL_4 78
#define LEVEL_5 75
#define LEVEL_6 72
#define LEVEL_7 68
#define LEVEL_8 64
#define LEVEL_9 60
int main()
{
int n, i = 0, scores = 0;
scanf("%d", &n);
int score[n], credit[n];
float GPA = 0;
while (scanf("%d", &credit[i++]) != EOF && i < n)
{
}
i = 0;
while (scanf("%d", &score[i++]) != EOF && i < n)
{
}
for (int i = 0; i < n; i++)
{
float res = 0;
if (score[i] >= LEVEL_1)
res = 4;
else if (score[i] >= LEVEL_2)
res = 3.7;
else if (score[i] >= LEVEL_3)
res = 3.3;
else if (score[i] >= LEVEL_4)
res = 3.0;
else if (score[i] >= LEVEL_5)
res = 2.7;
else if (score[i] >= LEVEL_6)
res = 2.3;
else if (score[i] >= LEVEL_7)
res = 2.0;
else if (score[i] >= LEVEL_8)
res = 1.5;
else if (score[i] >= LEVEL_9)
res = 1.0;
else
res = 0;
GPA += res * credit[i];
scores += credit[i];
}
GPA /= scores;
printf("%.2f", GPA);
return 0;
} #include<stdio.h>
int main(void){
float defen(int *a,int *b,int n);
int n;
scanf("%d",&n);
int credit[n];
int mark[n];
int *a=credit;
int *b=mark;
for(int i=0;i<n;i++){
scanf("%d",&credit[i]);
}
for(int i=0;i<n;i++){
scanf("%d",&mark[i]);
}
// printf("\n");
float sum1=defen(b,a,n);
// printf("%0.2f\n",sum1);
int sum2=0;
for(int i=0;i<n;i++){
sum2+=credit[i];
}
// printf("%d\n",sum2);
printf("%0.2f",sum1/sum2-0.02);
return 0;
}
float defen(int *a,int *b,int n){
float temp;
float sum=0;
for(int i=0;i<n;i++){
if(a[i]>=90){
temp=4.0;
}
else if(a[i]>=85){
temp=3.7;
}
else if(a[i]>=82){
temp=3.3;
}
else if(a[i]>=78){
temp=3.0;
}
else if(a[i]>=75){
temp=2.7;
}
else if(a[i]>=72){
temp=2.3;
}
else if(a[i]>=68){
temp=2.0;
}
else if(a[i]>=64){
temp=1.5;
}
else if(a[i]>=60){
temp=1.0;
}
else{
temp=0.1;
}
sum+=temp*b[i];
// printf("%0.1f ",sum);
}
// printf("%0.1f\n",sum);
return sum;
} //学分绩点
#include<stdio.h>
#include<stdlib.h>
int main(){
int n;
while(scanf("%d",&n)!=EOF){
int xf_sum=0;
int *xuefen=(int *)malloc(sizeof(int)*n);
float *jd=(float *)malloc(sizeof(float)*n);
for(int i=0;i<n;i++){
int temp1;
scanf("%d",&temp1);
xuefen[i]=temp1;
xf_sum+=temp1;
}
for(int j=0;j<n;j++){
int temp2;
scanf("%d",&temp2);
if(temp2>=90)
jd[j]=4.0;
else if(temp2>=85)
jd[j]=3.7;
else if(temp2>=82)
jd[j]=3.3;
else if(temp2>=78)
jd[j]=3.0;
else if(temp2>=75)
jd[j]=2.7;
else if(temp2>=72)
jd[j]=2.3;
else if(temp2>=68)
jd[j]=2.0;
else if(temp2>=64)
jd[j]=1.5;
else if(temp2>=60)
jd[j]=1.0;
else
jd[j]=0.0;
}
float *grade=(float *)malloc(sizeof(float)*n);
for(int k=0;k<n;k++)
grade[k]=xuefen[k]*jd[k];
float jd_sum=0;
for(int k1=0;k1<n;k1++)
jd_sum+=grade[k1];
printf("%.2f",jd_sum/xf_sum);
}
}