dalao们来看一下我用的一些函数有什么问题?

P1957 口算练习题

abc_mx @ 2022-08-03 17:42:04

#include<bits/stdc++.h>
using namespace std;
int n,aa,bb,cc;
char a[1001],ans[1001],las;
string s;
int main(){
    cin>>n;
    while(n--){
        fgets(s,sizeof(s),stdin);
        if(s[0]=='0'||s[0]=='1'||s[0]=='2') las=s[0],s[0]=' ';
        sscanf(s,"%d,%d",&aa,&bb);
        switch(las){
            case 'a': cc=aa+bb; sprintf(ans,"%d+%d=%d",aa,bb,cc);
            case 'b': cc=aa-bb; sprintf(ans,"%d-%d=%d",aa,bb,cc);
            case 'c': cc=aa*bb; sprintf(ans,"%d*%d=%d",aa,bb,cc);
        }
        printf("%s\n%d\n",ans,strlen(ans));
    }
    return 0;
} 

by xyf007 @ 2022-08-03 20:05:18

@bye_wjx char 大小为 1,所以数组长度就是最大长度


by abc_mx @ 2022-08-03 20:06:26

@xyf007 thx


上一页 |