乱七八糟的代码
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m;
int main()
{
cin>>n;
cin.get();
for(int i=1;i<=n;i++)
{
string s;
int k=1,dig[3]={0,0,0},ans,res,fu=0;
getline(cin,s);
ans=s.length();
for(int j=0;j<s.length();j++)
{
if(s[j]>='a'&&s[j]<='c')
{
m=s[j]=s[j]-'a'+1;
ans-=2;
j++;
continue;
}
if(s[j]==' ')
{
k=2;
continue;
}
if(s[j]=='-')
{
fu=1;
continue;
}
dig[k]*=10;
dig[k]+=s[j]-'0';
if(fu==1)
{
fu=0;
dig[k]+=-1;
}
}
cout<<dig[1];
if(m==1)
{
res=dig[1]+dig[2];
cout<<"+"<<dig[2]<<"="<<res<<endl;
}
if(m==2)
{
res=dig[1]-dig[2];
cout<<"-"<<dig[2]<<"="<<res<<endl;
}
if(m==3)
{
res=dig[1]*dig[2];
cout<<"*"<<dig[2]<<"="<<res<<endl;
}
if(res<0)ans++;
while(res)
{
res/=10;
ans++;
}
ans++;
if(dig[1]<0)ans++;
if(dig[2]<0)ans++;
cout<<ans<<endl;
}
return 0;
}