杭电2092哪错了。

jdtxse 2010-07-20 01:08:02
http://acm.hdu.edu.cn/showproblem.php?pid=2092地址
我这个代码哪里错了呢。
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
double a,b,x,y;

while(cin>>a>>b&&a&&b){
x=(a+sqrt(a*a-4*b))/2;//解方程,求根公式。,
y=(a-sqrt(a*a-4*b))/2;
if(x==(int)x&&y==(int)y) cout<<"YES"<<endl;//判断是不是整数。
else cout<<"NO"<<endl;
}
return 0;
}


...全文
120 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jdtxse 2010-07-20
  • 打赏
  • 举报
回复
谢谢[Quote=引用 2 楼 fanster28_ 的回复:]

C/C++ code
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
double a,b,x,y;

while(cin>>a>>b&&(a||b)){ //两个为0才退出
x=(a+sqrt(a*a-4*b))/2;
y=(a-sqr……
[/Quote]
WingStone 2010-07-20
  • 打赏
  • 举报
回复
1楼正解
zhuzeitou 2010-07-20
  • 打赏
  • 举报
回复
还有delta正负判断?直接sqrt不会出事么
fanster28_ 2010-07-20
  • 打赏
  • 举报
回复
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
double a,b,x,y;

while(cin>>a>>b&&(a||b)){ //两个为0才退出
x=(a+sqrt(a*a-4*b))/2;
y=(a-sqrt(a*a-4*b))/2;
if(x==(int)x&&y==(int)y) cout<<"Yes"<<endl;//输出大小写,下同
else cout<<"No"<<endl;
}
return 0;
}
michael122 2010-07-20
  • 打赏
  • 举报
回复
如果两者都为0,则输入结束

你这个1个为0,就结束了

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧