riki1230 @ 2023-03-28 20:10:31
#include <iostream>
using namespace std;
int main(){
int a,b;
char c;
cin>>a>>b>>c;
if(c=='+'){
cout<<a+b<<endl;
return 0;
}
if(c=='-'){
cout<<a-b<<endl;
return 0;
}
if(c=='*'){
cout<<a*b<<endl;
return 0;
}
if(c=='/'){
if(b==0){
cout<<"Divided by zero!"<<endl;
return 0;
}
cout<<a/b<<endl;
}
cout<<"Invalid operator!"<<endl;
return 0;
}
by riki1230 @ 2023-03-28 20:11:23
本地运行还可以
提交就WA了
by 幻想繁星 @ 2023-03-28 20:13:15
@yuanshanlishu hack如下
2 1 /
by tangrunxi @ 2023-03-28 20:14:04
@yuanshanlishu
#include <iostream>
using namespace std;
int main(){
int a,b;
char c;
cin>>a>>b>>c;
if(c=='+'){
cout<<a+b<<endl;
return 0;
}
if(c=='-'){
cout<<a-b<<endl;
return 0;
}
if(c=='*'){
cout<<a*b<<endl;
return 0;
}
if(c=='/'){
if(b==0){
cout<<"Divided by zero!"<<endl;
return 0;
}
cout<<a/b<<endl;
return 0;//这里加一行
}
cout<<"Invalid operator!"<<endl;
return 0;
}
by InversionShadow @ 2023-03-28 20:14:39
a/b
之后要 return 0
by riki1230 @ 2023-03-28 20:15:53
对对对
by riki1230 @ 2023-03-28 20:17:51
@[tangrunxi](/user/231147) @[yuandingquan1101](/user/672281) @[_1412_kid](/user/649095)
感谢各位大佬
(膜拜)