WA

P1957 口算练习题

ht20110603 @ 2022-10-30 13:55:19

代码+样例2输入输出


by ht20110603 @ 2022-10-30 14:03:12

AC了,原因:没考虑负数

code:

#include <bits/stdc++.h>
#define ll long long
#include <cstdio>
using namespace std;
int pd(int a){//暴力统计
    if(a>=0 and a<=9) return 1;
    if(a>=10 and a<=99) return 2;
    if(a>=100 and a<=999) return 3;
    if(a>=1000 and a<=9999) return 4;
    if(a>=10000 and a<=99999) return 5;
    if(a>=100000 and a<=999999) return 6;
    if(a>=1000000 and a<=9999999) return 7;
    if(a>=10000000 and a<=99999999) return 8;
    if(a>=100000000 and a<=999999999) return 9;
    if(a<=-1 and a>=-9) return 2;
    if(a<=-10 and a>=-99) return 3;
    if(a<=-100 and a>=-999) return 4;
    if(a<=-1000 and a>=-9999) return 5;
    if(a<=-10000 and a>=-99999) return 6;
    if(a<=-100000 and a>=-999999) return 7;
    if(a<=-1000000 and a>=-9999999) return 8;
    if(a<=-10000000 and a>=-99999999) return 9;
    if(a<=-100000000 and a>=-999999999) return 10;
}
int main(){
    int n,b,c,su,str=2;
    char a,b2[10],z;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b2;
        if(b2[0]>='a' && b2[0]<='z'){
            a=b2[0];
            cin>>b>>c;
        }else{
            sscanf(b2,"%d",&b);
            cin>>c;
        }
        if(a=='b'){
            su=b-c;
            cout<<b<<"-"<<c<<"=";
            printf("%d\n",su);
            str+=pd(b);
            str+=pd(c);
            str+=pd(su);
            cout<<str<<'\n';
        }
        else if(a=='c'){
            su=b*c;
            cout<<b<<"*"<<c<<"=";
            printf("%d\n",su);
            str+=pd(b);
            str+=pd(c);
            str+=pd(su);
            cout<<str<<'\n';
        }else{
            su=c+b;
            cout<<b<<"+"<<c<<"=";
            printf("%d\n",su);
            str+=pd(b);
            str+=pd(c);
            str+=pd(su);
            cout<<str<<'\n';
        }
        str=2;
    }
return 0;
}

|