全WA求助

P1957 口算练习题

TaamZeonhei @ 2021-10-10 17:57:53

第一个样本点输出结果与答案一致却还是WA怎么办?

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
    int ws(int a);
    int n;
    cin>>n;
    string line[n+1];
    int state,k=0;//k means the state is kept
    int x=0;
    int y=0;
    int gap;
    for(int i=0;i<n+1;i++)
    {
        getline(cin,line[i]);
    }
    for(int i=0;i<n+1;i++)
    {
        switch(line[i][0])
        {
            case 'a':state=1;k=0;break;
            case 'b':state=2;k=0;break;
            case 'c':state=3;k=0;break;
            default: k=1;
        }
        for(int ii=0;;ii++)
        {
            if(line[i][line[i].size()-1-ii]!=' ') y+=(line[i][line[i].size()-1-ii]-48)*pow(10,ii);
            else break;
            gap=(line[i].size()-1-ii)-1;
        }
        for(int ii=0;;ii++)
        {
            if(line[i][gap-1-ii]!=' '&&gap-1-ii!=-1) x+=(line[i][gap-1-ii]-48)*pow(10,ii);
            else break;
        }
        switch(state)
        {
            case 1:
                cout<<x<<'+'<<y<<'='<<x+y<<endl;
                cout<<ws(x)+ws(y)+ws(x+y)+2<<endl;
                break;
            case 2:
                cout<<x<<'-'<<y<<'='<<x-y<<endl;
                cout<<ws(x)+ws(y)+ws(x-y)+2<<endl;
                break;
            case 3:
                cout<<x<<'*'<<y<<'='<<x*y<<endl;
                cout<<ws(x)+ws(y)+ws(x*y)+2<<endl;
                break;
        }
        x=0;
        y=0;
    }
    return 0;
}
int ws(int a)
{
    int b=1;
    if(a<0) b++;
    for(;;)
    {
        a/=10;
        if(a==0) break;
        else b++;
    }
    return b;
}

by Shen_Linwood @ 2021-10-30 15:03:59

我最近没空 你可以去捞一下帖


上一页 |