求大佬看看哪里错了

P1957 口算练习题

qwe1471900575 @ 2021-03-02 00:53:27

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
    int n, i, a, b, c;
    cin >> n;
    char arr[100], bbc, arr2[100];
    while (n--)
    {
        fgets(arr, 100, stdin);
        if (arr[0] == 'a' || arr[0] == 'b' || arr[0] == 'c')
        {
            bbc = arr[0];
            arr[0] = ' ';
        }
        sscanf(arr, "%d %d", &a, &b);
        if (bbc == 'a')
        {
            sprintf(arr2, "%d+%d=%d", a, b, a + b);
        }
        else if (bbc == 'b')
        {
            sprintf(arr2, "%d-%d=%d", a, b, a - b);
        }
        else if (bbc == 'c')
        {
            sprintf(arr2, "%d*%d=%d", a, b, a * b);
        }
        printf("%s\n%d\n", arr2, strlen(arr2));
    }
    return 0;
}

by _Emiria_ @ 2021-03-02 10:55:46

哥咱用scanf,printf输入输出不好吗


|