70分,不知道卡哪里了,求解

P1957 口算练习题

小鲤鱼离线记 @ 2021-03-24 20:49:55

#define LENGTH 53
#include <stdio.h>
#include<stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
int main() {
    char a[LENGTH],b, c[LENGTH];
    int n=0,x,y;

    scanf("%d", &n);
    for (int  i = 0; i < n; i++)
    {
        scanf("%s", a);
        switch (a[0])
        {
            int temp;
        case 'a':
            scanf("%d%d", &x, &y);
            temp = x + y;
            sprintf(c,"%d+%d=%d", x, y,temp );
            printf("%s\n%d\n", c, strlen(c));
            break;
        case 'b':
            scanf("%d%d", &x, &y);
            temp = x - y;
            sprintf(c,"%d-%d=%d", x, y, temp);
            printf("%s\n%d\n", c, strlen(c));
            break;
        case 'c':
            scanf("%d%d", &x, &y);
            temp = x * y;
            sprintf(c,"%d*%d=%d", x, y, temp);
            printf("%s\n%d\n", c, strlen(c));
            break;
        default:
            x = atoi(a);
            scanf("%d",&y); 

            switch (b)
            {               
            case 'a':temp = x + y;b = '+';break;
            case 'b':temp = x - y;b = '-';break;
            case 'c':temp = x * y;  b = '*';break;
            }
            sprintf(c,"%d%c%d=%d", x,b, y, temp);
            printf("%s\n%d\n", c, strlen(c));
            break;
        }
        if (a[0]=='a'|| a[0] == 'b'|| a[0] == 'c')
          b = a[0];
    }
}

by _caiji_ @ 2021-03-24 21:27:04

你 b 到底存的是什么


by 小鲤鱼离线记 @ 2021-03-30 09:41:24

@caijianhong 存的是最近一个运算的运算符


|