90分样例错了,但本地运行是对的,求助大佬!

P1957 口算练习题

polygonolly @ 2022-12-22 11:53:25

Wrong Answer.wrong answer On line 1 column 3, read 4, expected +.

#include <iostream>
#include <cctype>
#include <stdlib.h>
using namespace std;
int main(){
    int s,i,n,m,a,b,c;
    cin>>i;
    char q[20],p[i+1];
    int aa[i],bb[i],cc[i],w[i];
    for(n=1;n<=i;n++){
        w[n]=2;
        cin>>q;
        if(isalpha(q[0])) {p[n]=q[0];cin>>a>>b;}
        else {a=atoi(q);cin>>b;p[n]=p[n-1];}
        if(p[n]=='a') m=a+b;
        else if(p[n]=='b') m=a-b;
        else if(p[n]=='c') m=a*b;
        aa[n]=a;
        bb[n]=b;
        cc[n]=m;
        if(a<=0) {a*=-1;w[n]++;}
        if(b<=0) {b*=-1;w[n]++;}
        if(m<=0) {m*=-1;w[n]++;}
        while(a>=1) {a=a/10;w[n]++;}
        while(b>=1) {b=b/10;w[n]++;}
        while(m>=1) {m=m/10;w[n]++;}} 
    for(n=1;n<=i;n++){
        cout<<aa[n];
        if(p[n]=='a') cout<<"+";
        else if(p[n]=='b') cout<<"-";
        else if(p[n]=='c') cout<<"*";
        cout<<bb[n]<<"="<<cc[n];
        cout<<endl<<w[n]<<endl;}
    return 0;
}

测试点:(同样例) 4 a 64 46 275 125 c 11 99 b 46 64


by limLine_2 @ 2022-12-28 10:41:28

我也是啊


by qianzhongye @ 2023-02-18 20:37:42

有没有一种可能,当结果<=0时,w[n]要+1


|