Chenyj29 @ 2022-02-08 12:15:03
#include <iostream>
#include <string>
using namespace std;
int b[20];
void number (string x){
while(x[0]>'9' || x[0]<'0') x=x.substr(1,x.size());
b[0]=0;
int i=0;
while(x[i]!=' '){
b[0]= b[0]*10 + (x[i]-'0');
i++;
}
while(x[i]==' ')i++;
b[1]=0;
while(i<x.size()){
b[1]= b[1]*10 + (x[i]-'0');
i++;
}
}
int length(int x){
if(x==0) return 1;
else{
int len=0;
if(x<0) len++;
x=abs(x);
while(x){
x=x/10;
len++;
}
return len;
}
}
int main(){
//freopen("1.txt","r", stdin);
int n;
cin>>n;
string a[100];
getline(cin,a[0]);
for (int i=0;i<n;i++){
getline (cin,a[i]);
if (a[i][0]>='0' &&a[i][0]<='9')
a[i]=a[i-1].substr(0,2) + a[i];
if (a[i][0]=='a') {
number (a[i]);
cout<<b[0]<<'+'<<b[1]<<'='<<b[0]+b[1]<<endl;
cout<<length(b[0])+length(b[1])+length(b[0]+b[1])+2<<endl;
}
if (a[i][0]=='b') {
number (a[i]);
cout<<b[0]<<'-'<<b[1]<<'='<<b[0]-b[1]<<endl;
cout<<length(b[0])+length(b[1])+length(b[0]+b[1])+2<<endl;
}
if (a[i][0]=='c') {
number (a[i]);
cout<<b[0]<<'*'<<b[1]<<'='<<b[0]*b[1]<<endl;
cout<<length(b[0])+length(b[1])+length(b[0]+b[1])+2<<endl;
}
}
return 0;
}
by EthanC_ @ 2022-02-08 12:22:33
您样例都没过啊