本地测的时候都是对的,一上OJ就无qwq
代码如下:
#include <bits/stdc++.h>
using namespace std;
string a;
char ope;
int s[2],cnts=1,ans,s1l,s2l,al;
int main(){
int o;
scanf("%d\n",&o);
for(int i=1;i<=o;i++){
getline(cin,a);
if(a[0]=='a') ope='+';
else if(a[0]=='b') ope='-';
else if(a[0]=='c') ope='*';
for(int k=10;k>=0;k--){
if(a[k]!='\000' && a[k]!=' '){
int temp=k;
for(int e=k;a[e]!=' ' && e>=0;e--){
s[cnts]+=pow(10,temp-e)*(a[e]-'0');
k=e;
}
if(cnts==-1) break;
else cnts--;
}
}
cnts=1;
if(ope=='+'){
ans=s[0]+s[1];
if(s[0]==0) s1l=1;
else s1l=log10(s[0])+1;
if(s[1]==0) s2l=1;
else s2l=log10(s[1])+1;
if(ans==0) al=1;
else al=log10(ans)+1;
cout<<s[0]<<'+'<<s[1]<<'='<<ans<<endl<<s1l+s2l+al+1+1;
if(i!=o) cout<<endl;
}
else if(ope=='-'){
ans=s[0]-s[1];
if(s[0]==0) s1l=1;
else s1l=log10(s[0])+1;
if(s[1]==0) s2l=1;
else s2l=log10(s[1])+1;
if(ans==0) al=1;
else if(ans<0) al=log10(abs(ans))+2;
else al=log10(ans)+1;
cout<<s[0]<<'-'<<s[1]<<'='<<ans<<endl<<s1l+s2l+al+1+1;
if(i!=o) cout<<endl;
}
else if(ope=='*'){
ans=s[0]*s[1];
if(s[0]==0) s1l=1;
else s1l=log10(s[0])+1;
if(s[1]==0) s2l=1;
else s2l=log10(s[1])+1;
if(ans==0) al=1;
else al=log10(ans)+1;
cout<<s[0]<<'*'<<s[1]<<'='<<ans<<endl<<s1l+s2l+al+1+1;
if(i!=o) cout<<endl;
}
memset(s,0,sizeof(s));
a="";
}
return 0;
}