lce11451410086 @ 2024-12-05 21:06:00
#include<bits/stdc++.h>
using namespace std;
char c[25000];
int main(){
int t;
scanf("%d",&t);
char last;
for(int sssss=1;sssss<=t;sssss++){
if(sssss==1){
getchar();
}
cin.getline(c,15);
int len=2;
char fu;
if(c[0]>='a'&&c[0]<='c'){
if(c[0]=='a'){
fu='+';
}else if(c[0]=='b'){
fu='-';
}else{
fu='*';
}
int num1=0,num2=0;
int s=0;
for(int i=2;c[i]!=' ';i++){
num1=num1*10+(c[i]-'0');
s=i;
}
for(int i=s+2;c[i]!='\0';i++){
num2=num2*10+int(c[i]-'0');
}
int sum=0;
if(fu=='+'){
sum=num1+num2;
}else if(fu=='-'){
sum=num1-num2;
}else if(fu=='*'){
sum=num1*num2;
}
if(sum<0){
len++;
}
int f=abs(sum);
int a=num1,b=num2;
for(int i=1;a!=0;i++,len++){
a/=10;
}
for(int i=1;b!=0;i++,len++){
b/=10;
}
for(int i=1;f!=0;i++,len++){
f/=10;
}
printf("%d%c%d=%d\n%d\n",num1,fu,num2,sum,len);
}else{
int num1=0,num2=0,s=0;
for(int i=0;c[i]!=' ';i++){
num1=num1*10+(c[i]-'0');
s=i;
}
for(int i=s+2;c[i]!='\0';i++){
num2=num2*10+int(c[i]-'0');
}
int sum=0;
if(last=='+'){
sum=num1+num2;
}else if(last=='-'){
sum=num1-num2;
}else if(last=='*'){
sum=num1*num2;
}
if(sum<0){
len++;
}
int f=abs(sum);
int a=num1,b=num2;
for(int i=1;a!=0;i++,len++){
a/=10;
}
for(int i=1;b!=0;i++,len++){
b/=10;
}
for(int i=1;f!=0;i++,len++){
f/=10;
}
printf("%d%c%d=%d\n%d\n",num1,fu,num2,sum,len);
last=' ';
}
last=fu;
}
return 0;
}
by pjh0625 @ 2024-12-05 21:19:09
@lce11451410086
#include<bits/stdc++.h>
using namespace std;
int n,x,y;
char ss[20],ans[100],k;
int main() {
scanf("%d",&n);
for(int i=1; i<=n; i++) {
scanf("%s",&ss);
if(isalpha(ss[0])) {
k=ss[0];
scanf("%d%d",&x,&y);
} else {
x=atoi(ss);
scanf("%d",&y);
}
if(k=='a')
sprintf(ans,"%d+%d=%d",x,y,x+y);
else if(k=='b')
sprintf(ans,"%d-%d=%d",x,y,x-y);
else
sprintf(ans,"%d*%d=%d",x,y,x*y);
printf("%s\n%d\n",ans,strlen(ans));
}
return 0;
}
by pjh0625 @ 2024-12-05 21:20:35
@lce11451410086
#include<bits/stdc++.h>
using namespace std;
int n,x,y;
char ss[20],ans[100],k;
int main() {
scanf("%d",&n);
for(int i=1; i<=n; i++) {
scanf("%s",&ss);
if(isalpha(ss[0])) {
k=ss[0];
scanf("%d%d",&x,&y);
} else {
x=atoi(ss);
scanf("%d",&y);
}
if(k=='a')
sprintf(ans,"%d+%d=%d",x,y,x+y);
else if(k=='b')
sprintf(ans,"%d-%d=%d",x,y,x-y);
else
sprintf(ans,"%d*%d=%d",x,y,x*y);
printf("%s\n%d\n",ans,strlen(ans));
}
return 0;
}
by sgjyzzb @ 2024-12-06 19:57:58
@lce11451410086如果2个运算数或者结果为0?
by lce11451410086 @ 2024-12-06 21:25:43
@pjh0625 那个isalpha是什么意思