c++ UVA 579 - ClockHands wrong answer
c++ UVA 579 - ClockHands wrong answer
我试图解决这个问题,但系统一直给我"错误的答案"。我检查了其他人的解决方案,我确信我的算法是正确的。有人能帮我吗?非常感谢。问题:UVA 579 ClockHands
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int hour, minute;
float hour_degree, minute_degree;
float total;
while(scanf("%d:%d",&hour, &minute) == 2)
{
if( hour == 0 && minute == 0)
break;
minute_degree = minute * 6;
hour_degree = hour * 30 + float(minute / 2);
total = fabs(hour_degree - minute_degree);
if(total > 180)
total = fabs(360 - total);
printf("%.3fn", total);
}
return 0;
}
我在中发现了一个错误
hour_degree = hour * 30 + float(minute / 2);
您正在进行整数除法,如果minute
是奇数,则会出错。应该是
hour_degree = hour * 30 + float(minute / 2.0);
相关文章:
- C++ is calculating wrong
- Is std::is_trivially_copyable wrong?
- 使用 Boost ASIO 和 SSL 时出现"Wrong Version Number"错误 (C++)
- 由于错误'wrong version number'无法完成握手
- 使用强制转换为"wrong"类型的指针算术
- QMap<int,QByteArray> return Wrong QByteArray
- "Static polymorphism with Qt signal/slot: What is wrong?"
- What wrong with `(A.array() == A.array()).matrix()`?
- 如何识别"wrong"指针
- msys2 和标头位于'wrong'位置
- 如何解决'path is wrong'编译错误,包括 GTKmm 3.0
- C++选择'wrong'默认参数的重载方法
- Wrong QModelIndex on QTreeView using custom QSortFilterProxy
- strcmp(x, str) is wrong?
- 代码块编译"wrong" cpp.sh 正确执行
- 代码厨师 Q - 为什么我会收到"Wrong Answer"错误
- c++ UVA 579 - ClockHands wrong answer
- VS-Android 在链接到共享库时生成"wrong"名称
- ARM Neon C: Wrong answer
- 显式运算符<<选择重载'wrong'