大家要利用scanf的输入格式判断属性,这个题就简单了,直接上代码

P1957 口算练习题

guosg @ 2020-11-12 10:33:26


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    char c;
    int n,m,a,b,s;
    char str[100];
    cin>>n;
    while(n--){
        m=scanf("%d %d",&a,&b);
        if(m==0){
            m=scanf("%c %d %d",&c,&a,&b);   
        }
        if(c=='a'){
            sprintf(str,"%d+%d=%d",a,b,a+b);
        }
        else if(c=='b'){
            sprintf(str,"%d-%d=%d",a,b,a-b);
        }
        else if(c=='c'){
            sprintf(str,"%d*%d=%d",a,b,a*b);
        }
        printf("%s\n%d\n",str,strlen(str));
    }
    return 0;
}

by fresh_boy @ 2020-11-12 10:35:22

%%%%%%%%


by Retired_lvmao @ 2020-11-12 10:49:17

sqlm


by Bbaka @ 2020-11-12 10:56:41

orz


by CE_WA_TLE @ 2020-11-12 10:58:21

%%%%%%%%这你都会!!!!!


by Van♂樣年华 @ 2020-11-12 12:00:59

%%%%%%%%%%%%%%%%%%%%%%%%%%%tql!!!!


by cxqghzj @ 2020-11-13 20:11:51

1%%%%%%%%%%%%%%%这你都会!!!!!


by _caiji_ @ 2020-11-16 20:35:35

sqlm,你这相当于讨论区题解


by downpour1 @ 2021-02-19 13:33:30

那同理也可以想到,sscanf是多余的,因为printf的返回值就是输出的字符个数,直接把printf的返回值存起来,再输出它,就不用进行字符串操作了


|