结果一样但是10分

P1957 口算练习题

Himner @ 2024-02-07 21:36:53

讨论区里面什么最后一排不能空行,一起输出,或者输入一行后再输出都试了一遍,睡觉都在想为什么只有10分。。。。。。

#include<stdio.h>
#include<string.h>
#include<cctype>

int main() {
    int n, i, x, y;
    char ch = 0, alp = 0, out[50][20] = {0};
    scanf("%d\n", &n);
    for (i = 0; i < n; i++) {
        ch = getchar();
        if (isalpha(ch))
            alp = ch;
        else
            ungetc(ch, stdin);
        scanf("%d %d", &x, &y);
        getchar();
        switch (alp) {
        case 'a':
            sprintf(out[i], "%d+%d=%d", x, y, x + y);
            break;
        case 'b':
            sprintf(out[i], "%d-%d=%d", x, y, x - y);
            break;
        case 'c':
            sprintf(out[i], "%d*%d=%d", x, y, x * y);
            break;
        default:
            break;
        }
    }
    for (i = 0; i < n; i++) {
        if (i == n - 1) {
            printf("%s\n%d", out[i], strlen(out[i]));
            return 0;
        }
        printf("%s\n%d\n", out[i], strlen(out[i]));
    }
    return 0;
}

by Himner @ 2024-02-07 21:45:34

逛了半天讨论区发现洛谷不能用getchar...... 太6了。


|