yyyymh @ 2022-04-03 10:42:15
代码如下:
#include <bits/stdc++.h>
using namespace std;
int wtf(int n,int m){
int s=n;
for(int i=1;i<=m-1;i++){
n*=s;
}
return n;
}
int chao(int n){
int sum=0;
if(n<0){
sum=1;
n*=-1;
}
while(n>0){
n/=10;
sum++;
}
return sum;
}
int main(){
int n,b,c;
cin>>n;
char a,q;
for(int i=1;i<=n;i++){
cin>>a>>b>>c;
if(a!='a'&&a!='b'&&a!='c'){
b+=wtf(10,chao(b))*(int(a)-48);
if(q=='a'){
cout<<b<<"+"<<c<<"="<<b+c<<endl<<chao(b)+chao(c)+chao(b+c)+2<<endl;
}
else if(q=='b'){
cout<<b<<"-"<<c<<"="<<b-c<<endl<<chao(c)+chao(b)+chao(b-c)+2<<endl;
}
else{
cout<<b<<"*"<<c<<"="<<b*c<<endl<<chao(c)+chao(b)+chao(b*c)+2<<endl;
}
}
else{
q=a;
if(q=='a'){
cout<<b<<"+"<<c<<"="<<b+c<<endl<<chao(b)+chao(c)+chao(b+c)+2<<endl;
}
else if(q=='b'){
cout<<b<<"-"<<c<<"="<<b-c<<endl<<chao(c)+chao(b)+chao(b-c)+2<<endl;
}
else{
cout<<b<<"*"<<c<<"="<<b*c<<endl<<chao(c)+chao(b)+chao(b*c)+2<<endl;
}
}
}
return 0;
}
一旦输入的是a,输出的时候b和c就一样了 例子: a 1 2 输出: 1+1=3 5
by yyyymh @ 2022-04-03 10:43:00
那个 1+1=3后面的5是算式长度