别的我都能理解但是这个�@我无法理解

P1957 口算练习题

6lszxz @ 2021-12-05 11:10:13

#include "cstdio"
#include "iostream"
#include "algorithm"
#include "string.h"

using namespace std;

int main()
{
    char last;
    char s[20];
    char answer[20];
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int a,b;
        fgets(s,sizeof s,stdin);
        if(s[0]=='a'||s[0]=='b'||s[0]=='c')
        {
            last=s[0];
            s[0]=' ';
        }
        sscanf(s,"%d%d",&a,&b);
        switch (last)
        {
            case 'a':
                sprintf(answer,"%d+%d=%d",a,b,a+b);
                break;
            case 'b':
                sprintf(answer,"%d-%d=%d",a,b,a-b);
                break;
            case 'c':
                sprintf(answer,"%d*%d=%d",a,b,a*b);
                break;

        }
        cout<<answer<<endl<<strlen(answer)<<endl;
    }

    return 0;
}

用样例输入的时候第一行出来个�@呜呜


by Justin090102 @ 2021-12-05 11:20:12

@6lszxz ide运行输出错误了,4210104+0=4210104


|