1 条题解

  • 0
    @ 2026-10-12 11:41:41

    题目大意

    依次读入字符、整数、单精度浮点数、双精度浮点数,用空格分隔输出,浮点数保留 6 位小数。

    解题思路

    • 字符:scanf(" %c", &c)(%c 前加空格跳过换行,这是关键技巧);
    • 整数:%d;
    • 单精度 float:读入用 %f;
    • 双精度 double:读入用 %lf;
    • 输出时 float 和 double 都可以用 %f(默认 6 位小数)或 %.6f。

    样例:a 12 2.300000 3.200000 ✓

    易错点

    • %c 不跳空白字符,前面输入留下的换行会被它读走,务必写 " %c";
    • float 读入用 %f,double 读入用 %lf,别混。

    参考代码

    #include <stdio.h>
    
    int main() {
        char c;
        int n;
        float f;
        double d;
        scanf(" %c", &c);
        scanf("%d", &n);
        scanf("%f", &f);
        scanf("%lf", &d);
        printf("%c %d %.6f %.6f\n", c, n, f, d);
        return 0;
    }
    
    • 1

    信息

    ID
    464
    时间
    1000ms
    内存
    128MiB
    难度
    10
    标签
    递交数
    6
    已通过
    4
    上传者