RE和WA求调
查看原帖
RE和WA求调
1629237
LTsurvive楼主2025/1/11 10:45

写了两个,第一个提交是RE,第二个是WA,并且测试点变一个了

#include <bits/stdc++.h>
using namespace std;

int main(){
	int one,two;
	char f;
	cin>>one>>two>>f;
	if(two==0&&f=='/'){
		cout<<"Divided by zero!"<<endl;
	}
	if(f=='+'){
		cout<<one+two<<endl;
	}else if(f=='-'){
		cout<<one-two<<endl;
	}else if(f=='*'){
		cout<<one*two<<endl;
	}else if(f=='/'){
		cout<<one/two<<endl;
	}else{
		cout<<"Invalid operator!"<<endl;
	}
}
#include <bits/stdc++.h>
using namespace std;

int main(){
	int a,b,y;
	char c;
	cin>>a>>b>>c;
	bool x;
	switch (c) {
	case '+':
		y=a+b;
		break;
	case '-':
		y=a-b;
		break;
	case '*':
		y=a*b;
		break;
	case '/':
		if(b==0){
			x=true;
		}else{
			y=a/b;
		}
		break;
	default:
		cout<<"Invalid operator!"<<endl;
		exit(0);
	}
	if(x){
		cout<<"Divided by zero!"<<endl;
	}else{
		cout<<y<<endl;
	}
}
2025/1/11 10:45
加载中...