题解 | #学生基本信息输入输出#
学生基本信息输入输出
https://www.nowcoder.com/practice/58b6a69b4bf943b49d2cd3c15770b9fd
#include <stdio.h>
int main() {
char a[100]={0};//用字符存储,防止id过长,int类型存不下
char tmp_a;
double score[3]={0};
int tmp=0;
int i=0;
while((tmp_a=getchar())!=';')//根据输入可知,id之后会输入';',可用于作为id的结尾
{
a[i]=tmp_a;
i++;
}
scanf("%lf,%lf,%lf",&score[0],&score[1],&score[2]);//输入成绩
for(i=0;i<3;i++)
{
score[i]=score[i]*100;//乘100可保留2位小数,然后可以使用之前实现四舍五入的算法
tmp=(int)(score[i]+0.5);//int为向下取整
score[i]=tmp/100.0;
}
printf("The each subject score of No. %s is %.2lf, %.2lf, %.2lf.",a,score[0],score[1],score[2]);
return 0;
}
查看7道真题和解析