为何wa了两个点呐!

P1957 口算练习题

lrc_mttf001 @ 2020-08-11 14:29:29

感觉。。。好像。。。没毛病?

#include<bits/stdc++.h>
using namespace std;
int main() {
    freopen("P1957_2.in","r",stdin);
    int n,mi=1,xb;
    string c="",x="",x1="",x2="";
    cin>>n;
    for(int i=0; i<n; i++) {
        stringstream ss,sa,sc;
        cin>>c;
        if(c[0]>='a'&&c[0]<='c') {
            xb=c[0]-'a';
            switch(xb) {
                case 0:
                    cin>>x>>x1;
                    int a,b,m;
                    ss<<x;
                    ss>>a;
                    sa<<x1;
                    sa>>b;
                    m=a+b;
                    sc<<m;
                    x2=sc.str();
                    cout<<x<<'+'<<x1<<'='<<x2<<endl<<x2.size()+2+x.size()+x1.size()<<endl;
                    break;
                case 1:
                    cin>>x>>x1;
                    ss<<x;
                    ss>>a;
                    sa<<x1;
                    sa>>b;
                    m=a-b;
                    sc<<m;
                    x2=sc.str();
                    cout<<x<<'-'<<x1<<'='<<x2<<endl<<x2.size()+2+x.size()+x1.size()<<endl;
                    break;
                case 2:
                    cin>>x>>x1;
                    ss<<x;
                    ss>>a;
                    sa<<x1;
                    sa>>b;
                    m=a*b;
                    sc<<m;
                    x2=sc.str();
                    cout<<x<<'*'<<x1<<'='<<x2<<endl<<x2.size()+2+x.size()+x1.size()<<endl;
                    break;
            }
        } else
            switch(xb) {
                case 0:
                    cin>>x;
                    int a,b,m;
                    ss<<c;
                    ss>>a;
                    sa<<x;
                    sa>>b;
                    m=a+b;
                    sc<<m;
                    x2=sc.str();
                    cout<<c<<'+'<<x<<'='<<x2<<endl<<x2.size()+2+x.size()+c.size()<<endl;
                    break;
                case 1:
                    cin>>x;
                    ss<<c;
                    ss>>a;
                    sa<<x;
                    sa>>b;
                    m=a-b;
                    sc<<m;
                    x2=sc.str();
                    cout<<c<<'-'<<x<<'='<<x2<<endl<<x2.size()+2+x.size()+c.size()<<endl;
                    break;
                case 2:
                    cin>>x>>x1;
                    ss<<x;
                    ss>>a;
                    sa<<x1;
                    sa>>b;
                    m=a*b;
                    sc<<m;
                    x2=sc.str();
                    cout<<x<<'*'<<x1<<'='<<x2<<endl<<x2.size()+2+x.size()+x1.size()<<endl;
                    break;
            }
    }
}

by Unordered_OIer @ 2020-08-11 14:33:06

我怎么觉得不用那么多代码呢


by congxia @ 2020-08-11 14:58:32

我怎么觉得不用那么多代码呢


|