为什么样例和第一个数据都一样了,但全部WA?

P1957 口算练习题

Bqr_Love_HYZ @ 2022-04-28 13:52:34

RT

#include <bits/stdc++.h>
using namespace std;

long long ws(long long n){
    long long m = n,cnt = 0;
    if(n < 0) ++cnt;
    while(m){
        m /= 10;
        ++cnt;
    }
    return cnt;
}

long long hyz(char ch){
    long long a;
    a = ch - '0';
    char chh;
    while(chh = getchar() != ' '){
        a = 10*a + chh - '0';
    }
    return a;
}

int main(){
    long long n; scanf("%lld",&n);
    ++n;
    while(n--){
        string s;
        char ch;
        long long a = 0,b = 0;
        getline(cin,s);
        if(isdigit(s[0])){
            ch = 'a';
            long long i;
            for(i=0;s[i]!=' ';++i){
                a = 10*a + s[i] - '0';
            }
            for(long long j=i+1;s[j]!='\0';++j){
                b = 10*b + s[j] - '0';
            }
        }
        else{
            ch = s[0];
            long long i;
            for(i=2;s[i]!=' ';++i){
                a = 10*a + s[i] - '0';
            }
            for(long long j=i+1;s[j]!='\0';++j){
                b = 10*b + s[j] - '0';
            }
        }
        switch(ch){
            case 'a':printf("%lld+%lld=%lld\n%lld\n",a,b,a+b,ws(a)+ws(b)+2+ws(a+b)); break;
            case 'b':printf("%lld-%lld=%lld\n%lld\n",a,b,a-b,ws(a)+ws(b)+2+ws(a-b)); break;
            case 'c':printf("%lld*%lld=%lld\n%lld\n",a,b,a*b,ws(a)+ws(b)+2+ws(a*b)); break;
        }
    }
    return 0;
}

P1957_1.in:\ 1\ a 99 999

P1957_1.out:\ 99+999=1098\ 11

为什么啊啊啊啊……求助QAQ


by Bqr_Love_HYZ @ 2022-04-28 13:54:42

啊啊啊打错了后面数据多了'\'

'\'代表换行!


by 编码落寞 @ 2022-04-28 15:20:59

@Bqr_Love_HYZ

我这里显示你程序并没有过样例。 加法那里第二个数据不对


by 编码落寞 @ 2022-04-28 15:31:06

@编码落寞

s[j]!='\0'

改成

s[j]>='0'&&s[j]<='9'

by Bqr_Love_HYZ @ 2022-04-28 18:30:50

@编码落寞 嘤嘤嘤我鸡道哪里错了 谢谢你!


|