TaamZeonhei @ 2021-08-09 16:42:24
#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;
int x=0;
int y=0;
int gap;
for(int i=0;i<=n;i++)
{
getline(cin,line[i]);
}
for(int i=1;i<=n;i++)
{
switch(line[i][0])
{
case 'a':state=1;break;
case 'b':state=2;break;
case 'c':state=3;break;
}
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;
}
//cout<<endl<<i<<":"<<state<<endl<<endl;//
x=0;
y=0;
}
return 0;
}
int ws(int a)
{
int b;
if(a>=0&&a<10) b=1;
else if(a>=10&&a<100) b=2;
else if(a>=100&&a<1000) b=3;
else if(a>=1000&&a<10000) b=4;
else if(a<0&&a>-10) b=2;
else if(a<=-10&&a>-100) b=3;
else if(a<=-100&&a>-1000) b=4;
else if(a<=-1000&&a>-10000) b=5;
return b;
}
手动测试样例通过,第一个数据点也与答案相符,但全WA。跪求大神解答。