求助
查看原帖
求助
638141
Literally114514楼主2022/12/11 20:50

这题我用的分类讨论,改了十几次后还是WA*3

提交记录

#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int x,y,z;
	cin>>x>>y>>z;
	if(y<x && y<z && x<z && z>0 && y>0 && x>0){
		cout<<"-1";
		return 0;
	}
	if(x<z && y<x && y<z && x>0 && z>0 && y>0){
		cout<<"-1";
		return 0;
	}
	if(x<z && x<y && z<y && x<0 && z<0 && y<0){
		cout<<"-1";
		return 0;
	}
	if(z<x && z<y && x<y && x<0 && z<0 && y<0){
		cout<<"-1";
		return 0;
	}
	if(x<0){
		if(y>0){
			cout<<abs(x);
		}else{
			if(z>0){
				cout<<2*abs(z)+abs(x);
			}else{
				cout<<abs(x);
			}
		}
	}else{
		if(y<0){
			cout<<x;
		}else{
			if(z<0){
				cout<<2*abs(z)+x;
			}else{
				cout<<x;
			}
		}
	}
	return 0;
}
2022/12/11 20:50
加载中...