运用if来完成,感觉我的代码有点卡bug
2025-08-03 21:01:43
发布于:四川
1阅读
0回复
0点赞
我的实力有点差,看到题我先想到的是运用if来完成,毕竟最后输出是只有YES,NO,看着有点麻烦,但胜在好理解,其实过程中的if(d>=dist||dist>=d) cout<<"Yes";我是感觉有问题的,但最后通过了,有大神能顺便帮我看看嘛
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
int g = abs(c - b);
int dist = min(abs(c - a), abs(c - b));
if(c<=a){
if(c + d >= a) cout<<"Yes";
else cout<<"No";
}
else{
if(a<=c&&b>=c){
if(d>=dist||dist>=d) cout<<"Yes";
else cout<<"No";
}
else{
if (abs(c - b) <= d) cout << "Yes";
else cout<<"No";
}
}
return 0;
}
这里空空如也
有帮助,赞一个