首页 > 试题广场 >

学生基本信息输入输出

[编程题]学生基本信息输入输出
  • 热度指数:238032 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
依次输入一个学生的学号,以及3科(C语言,数学,英语)成绩,在屏幕上输出该学生的学号,3科成绩(注:输出成绩时需进行四舍五入且保留2位小数)。

数据范围:学号满足 ,各科成绩使用百分制,且不可能出现负数

输入描述:
学号以及3科成绩,学号和成绩之间用英文分号隔开,成绩之间用英文逗号隔开。


输出描述:
学号,3科成绩,输出格式详见输出样例。
示例1

输入

17140216;80.845,90.55,100.00

输出

The each subject score of No. 17140216 is 80.85, 90.55, 100.00.
示例2

输入

123456;93.33,99.99,81.20

输出

The each subject score of No. 123456 is 93.33, 99.99, 81.20.
#include <stdio.h>

int main() {
int n = 0;
double c = 0.0;
double math = 0.0;
double english = 0.0;
scanf("%d;%lf,%lf,%lf",&n,&c,&math,&english);
printf("The each subject score of No. %d is %.2f, %.2f, %.2f.\n", n, c + 1e-9, math + 1e-9, english + 1e-9);
return 0;
}



发表于 2025-09-13 10:03:07 回复(0)
#include <stdio.h>
int main()
{
    int id = 0;
    float c = 0.0, s = 0.0, e = 0.0;
    scanf("%d,%f,%f,%f", &id, &c, &s, &e);
    printf("The each subject score of No. %d is %.2f,%.2f,%.2f", id, c, s, e);
    return 0;
}哪里错了啊就是提交不上去

发表于 2025-09-01 10:47:13 回复(1)
#include <stdio.h>
#include <math.h>

int main() {
    float a, b, c;
    int d;
    scanf("%d;%f,%f,%f", &d, &a, &b, &c);
    a=round (a*100)/100;
    b=round (b*100)/100;
    c=round (c*100)/100;
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.", d, a, b, c);

    return 0;
}
发表于 2025-08-18 19:23:12 回复(0)
#include <stdio.h>

// 四舍五入保留两位小数
float qqq(float num)
{
    num = num * 100;
    if (num - (int)num >= 0.5)
    {
        num = (int)num + 1;
    }
    else
    {
        num = (int)num;
    }
    return num / 100.00;
}

int main() {
    int id;
    float c_score, math_score, english_score;
    
    // 读取输入数据,按照格式解析
    scanf("%d;%f,%f,%f", &id, &c_score, &math_score, &english_score);
    
    // 四舍五入保留两位小数
    c_score = qqq(c_score);
    math_score = qqq(math_score);
    english_score = qqq(english_score);
    
    // 输出结果
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.\n", 
           id, c_score, math_score, english_score);
    
    return 0;
}

发表于 2025-08-12 15:06:27 回复(0)
#include <stdio.h>
float roundedNumber(float m);
int main(void) {
    unsigned int studentId = 0;
    float cLanguageScore, mathScore, englishScore;
    scanf("%u;%f,%f,%f", &studentId, &cLanguageScore, &mathScore, &englishScore);
    printf("The each subject score of No. %u is %.2f, %.2f, %.2f.", studentId,
           roundedNumber(cLanguageScore), roundedNumber(mathScore),
           roundedNumber(englishScore) );
    return 0;
}
float roundedNumber(float m) {
    return ((int)(m * 100 + 0.5) / 100.0);
}
发表于 2025-08-04 23:52:49 回复(0)
#include <stdio.h>

int main() {
    int num;
    float a, b, c;
    scanf("%d;%f,%f,%f",&num,&a,&b,&c);
    a = (a*1000+0.5)/1000;
    b = (b*1000+0.5)/1000;
    c = (c*1000+0.5)/1000;
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",num,a,b,c);
    return 0;
}
发表于 2025-07-30 17:16:53 回复(0)
#include <stdio.h>

int main() 
{
    int a;
   float b=0.0f;
    float c=0.0f;
    float d=0.0f;
    scanf("%d;%f,%f,%f", &a, &b,&c,&d); 
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.\n", a,b,c,d);
    return 0;
}
 求大神解惑:为什么我的调试和自测结果都对,但是提交结果总是
第一个浮点数不能四舍五入?
发表于 2025-07-14 10:26:30 回复(1)
#include <stdio.h>

int main() {
    int id;
    double score1, score2, score3;
    scanf("%d;%lf,%lf,%lf", &id, &score1, &score2, &score3);
    
    // 添加0.0005偏移确保四舍五入正确
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.", 
           id, 
           score1 + 0.0005,
           score2 + 0.0005,
           score3 + 0.0005);
    return 0;
}
float类型用不了,四舍五入的精度不够,让人很费解
发表于 2025-06-14 11:51:33 回复(2)
我这个一直报错是什么原因

#include <stdio.h>
double a, b, c;
unsigned int xuehao;
int main()
{
	scanf("%d;%lf,%lf,%lf", &xuehao, &a, &b, &c);//scanf可以实现一次获取多个不同类型的按键值
	printf("The each subject score of No. %d is %.2lf, %.2lf, %.2lf.", xuehao, a, b, c);
	return 0;

}

发表于 2025-05-22 17:01:22 回复(1)
#include <stdio.h>
float sheru(float q){
    int x=0;
    x=(int)(q*1000)%10;
    if(x>4) q=q+0.01-x*0.001;
    else q=q-x*0.001;
    return q;
}
int main() {
    long number=0;
    float c=0,m=0,e=0;
    scanf("%ld;%f,%f,%f",&number,&c,&m,&e);
    c=sheru(c);
    m=sheru(m);
    e=sheru(e);
    printf("The each subject score of No. %ld is %.2f, %.2f, %.2f.",number,c,m,e);
    return 0;
}
这样子可以通过,我猜大概率是浮点数存储有误差,导致有时候没法很好做到四舍五入。我这里定义了一个函数可以稍微纠正一下;
发表于 2025-04-16 00:34:28 回复(0)
为什么有一组不对,四舍五入的问题 ,搞不懂   
float=0.0f;
    float j=0.0f;
    float k=0.0f;
    int a=0;
    scanf("%d;%f,%f,%f",&a,&i,&j,&k);
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.\n",a,i,j,k);

发表于 2025-02-12 13:29:14 回复(2)
#include <math.h>
#include <stdio.h>

int main() 
{
    int SuID = 0;
    float C = 0;
    float math = 0;
    float Eg = 0;
    scanf("%d;%f,%f,%f",&SuID,&C,&math,&Eg);
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",SuID,round(C * 100) / 100,math,Eg);
    return 0;
}
//C语言成绩这里因为浮点数存储有不准确性,所以有概率出现四舍五入不对的情况,这个时候要用round(变量 * 100) / 100 来让浮点数变得具有准确性

发表于 2025-01-19 14:33:06 回复(4)
#include <stdio.h>
int main()
{
    int a;
    float b = 0.0f;
    float c = 0.0f;
    float d = 0.0f;
    scanf("%d;%f,%f,%f", &a, &b, &c, &d);
    printf("The each subject score of No. %d is %.2f, %.2f, %.2f.\n", a, b, c, d);
    return 0;
}
这代码为什么不会四舍五入
发表于 2025-01-16 16:45:40 回复(2)
#include <stdio.h>
struct stu {
    int n;
    float C;
    float Math;
    float English;
};

int main() {
    struct stu s = {0,0.0f,0.0f,0.0f};
    scanf("%d;%f,%f,%f",&s.n,&s.C,&s.Math,&s.English);
    if (s.n >= 1 && s.n <= 20000000 && s.C >= 0 && s.Math >= 0 && s.English >= 0) {
        printf("The each subject score of No. %d is %.2f, %.2f, %.2f.",s.n,s.C,s.Math,s.English);
    }
    return 0;
}
发表于 2024-12-31 19:56:24 回复(0)
#include <stdio.h>

int main() {
    int a;
    float b,c,d;
    scanf("%d%f%f%f",&a,&b,&c,&d);
    if(a>=1&&a<=20000000){
        printf("The each subject score of No. %d is %.2f,%.2f,%.2f",a,b,c,d);
    }
    return 0;
}大佬们请帮忙看看为什么出错
发表于 2024-12-21 14:44:33 回复(1)
#include <stdio.h>
int main() {
    float a , b , c ;
     int n;
    scanf("%d", &n);
    scanf("%f%f%f", &a, &b, &c);
    printf("The each subject score No.%d is %.2f, %.2f, %.2f.\n", n, a, b, c);
    return 0;
}为什么这个代码错误
发表于 2024-11-24 18:15:16 回复(1)
#include <stdio.h>
double sol(double x)
{
    int e = x * 1000, f = x * 100, h = f * 10, g = e - h;
    double F = f;
    if (g < 5)
    {
        double z = 0;
        z = F / 100;
        return z;
    }
    else
    {
        double z = 0;
        z = ++F / 100;
        return z;
    }
}
int main(void)
{
    double a = 0, b = 0, c = 0;
    unsigned long long int d = 0;
    scanf("%llu;%lf,%lf,%lf", &d, &a, &b, &c); //这要求符号隔开,起码vs2022最好用空格或者干脆不隔开,容易出问题
    double A = sol(a);
    double B = sol(b);
    double C = sol(c);
   /* double eps = 1e-8;
    a = a + eps;
    b = b + eps;
    c = c + eps;*/
    printf("The each subject score of No. %llu is %.2lf, %.2lf, %.2lf.", d, A, B, C);
    return 0;
}
发表于 2024-11-10 15:49:52 回复(1)
#include <stdio.h>

int main()
{
    int a;//the number
    double b,c,d;//three scores
    scanf("%d;%lf,%lf,%lf",&a,&b,&c,&d);
    printf("The each subject score of No. %d is %.2lf, %.2lf, %.2lf.",a,b,c,d);
    return 0;
}

发表于 2024-10-23 19:43:17 回复(3)
#include <stdio.h>
int main()
{
    int a = 0;//学号
    double b = 0.00;//c语言成绩
    double c = 0.00;//数学成绩
    double d = 0.00;//英语成绩

    scanf("%d;%lf,%lf,%lf", &a,&B,&C,&D);
    if (a >= 1, a <= 20000000 && B >= 0 && C >= 0 && D >= 0)//限制条件,养成习惯
    {
        double b = (int)((B * 100) + 0.5) / 100.0;//四舍五入
        double c = (int)((C * 100) + 0.5) / 100.0;//四舍五入
        double d = (int)((D * 100) + 0.5) / 100.0;//四舍五入
        printf("The each subject score of No. %d ",a);
        printf("is %.2lf, ", b);
        printf("%.2lf, ", c);
        printf("%.2lf.", d);
        //.2的意思是保留小数点后两位
    }
    else
    {
        printf("错误");
    }

    return 0;
}
发表于 2024-10-20 21:09:23 回复(0)

问题信息

上传者:牛客309119号
难度:
88条回答 8881浏览

热门推荐

通过挑战的用户

查看代码
学生基本信息输入输出