XieXiangLa @ 2023-07-16 11:05:01
Devc++样例全过了,但是0分
#include<bits/stdc++.h>
using namespace std;
string py;
int main() {
int n;
cin>>n;
string s1, s2, s3;
for(int i=0; i<2*n; i++) {
cin>>s1;
if(s1=="a") {
py="+";
cin>>s2>>s3;
int sum=stoi(s2)+stoi(s3);
string s4=to_string(sum);
string ss=s2+"+"+s3+"="+s4;
printf("%d+%d=%d\n%d\n", stoi(s2), stoi(s3), sum, ss.size());
} else if(s1=="c") {
py="*";
cin>>s2>>s3;
int sum=stoi(s2)*stoi(s3);
string s4=to_string(sum);
string ss=s2+"*"+s3+"="+s4;
printf("%d*%d=%d\n%d\n", stoi(s2), stoi(s3), sum, ss.size());
} else if(s1=="b") {
py="-";
cin>>s2>>s3;
int sum=stoi(s2)-stoi(s3);
string s4=to_string(sum);
string ss=s2+"-"+s3+"="+s4;
printf("%d-%d=%d\n%d\n", stoi(s2), stoi(s3), sum, ss.size());
} else {
if(py=="+") {
cin>>s2;
int sum=stoi(s1)+stoi(s2);
string s3=to_string(sum);
string ss=s1+"+"+s2+"="+s3;
printf("%d+%d=%d\n%d\n", stoi(s1), stoi(s2), sum, ss.size());
} else if(py=="*") {
cin>>s2;
int sum=stoi(s1)*stoi(s2);
string s3=to_string(sum);
string ss=s1+"*"+s2+"="+s3;
printf("%d*%d=%d\n%d\n", stoi(s1), stoi(s2), sum, ss.size());
} else if(py=="-") {
cin>>s2;
int sum=stoi(s1)-stoi(s2);
string s4=to_string(sum);
string ss=s1+"-"+s2+"="+s3;
printf("%d-%d=%d\n%d\n", stoi(s1), stoi(s2), sum, ss.size());
}
}
}
}
by White_Falcon @ 2023-07-16 11:19:45
嗨嗨嗨
by White_Falcon @ 2023-07-16 11:20:03
让我看看
by White_Falcon @ 2023-07-16 11:22:18
我这边运行不了呀...
by White_Falcon @ 2023-07-16 11:23:28
@XieXiangLa
by PC114514 @ 2023-07-16 11:23:49
改完了
#include<bits/stdc++.h>
using namespace std;
string py;
int main() {
int n;
cin>>n;
string s1, s2, s3;
for(int i=0; i<n; i++) {
cin>>s1;
if(s1=="a") {
py="+";
cin>>s2>>s3;
int sum=stoi(s2)+stoi(s3);
string s4=to_string(sum);
string ss=s2+"+"+s3+"="+s4;
printf("%d+%d=%d\n%d\n", stoi(s2), stoi(s3), sum, ss.size());
} else if(s1=="c") {
py="*";
cin>>s2>>s3;
int sum=stoi(s2)*stoi(s3);
string s4=to_string(sum);
string ss=s2+"*"+s3+"="+s4;
printf("%d*%d=%d\n%d\n", stoi(s2), stoi(s3), sum, ss.size());
} else if(s1=="b") {
py="-";
cin>>s2>>s3;
int sum=stoi(s2)-stoi(s3);
string s4=to_string(sum);
string ss=s2+"-"+s3+"="+s4;
printf("%d-%d=%d\n%d\n", stoi(s2), stoi(s3), sum, ss.size());
} else {
if(py=="+") {
cin>>s2;
int sum=stoi(s1)+stoi(s2);
string s3=to_string(sum);
string ss=s1+"+"+s2+"="+s3;
printf("%d+%d=%d\n%d\n", stoi(s1), stoi(s2), sum, ss.size());
} else if(py=="*") {
cin>>s2;
int sum=stoi(s1)*stoi(s2);
string s3=to_string(sum);
string ss=s1+"*"+s2+"="+s3;
printf("%d*%d=%d\n%d\n", stoi(s1), stoi(s2), sum, ss.size());
} else if(py=="-") {
cin>>s2;
int sum=stoi(s1)-stoi(s2);
string s3=to_string(sum);
string ss=s1+"-"+s2+"="+s3;
printf("%d-%d=%d\n%d\n", stoi(s1), stoi(s2), sum, ss.size());
}
}
}
}
by PC114514 @ 2023-07-16 11:25:10
第一是为什么要循环2n次,导致WA 第二是在48行 没有运算符运行减法时s3打成了s4
by White_Falcon @ 2023-07-16 11:25:51
哦,我好了
by PC114514 @ 2023-07-16 11:26:03
AC记录