http://codevs.cn/problem/1203/

1203 判断浮点数是否相等

 

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 青铜 Bronze
 
 
题目描述 Description
给出两个浮点数,请你判断这两个浮点数是否相等
输入描述 Input Description
输入仅一行,包含两个浮点数
输出描述 Output Description
输出仅一行,如果相等则输出yes,否则输出no。
样例输入 Sample Input
2.980000001 2.9800000000001
样例输出 Sample Output
yes
数据范围及提示 Data Size & Hint
我们一般认为两个浮点数相等,当且当他们之间的误差不超过1e-8。
 
分析:
 
水题
 
AC代码:
 
 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <string.h>
 5 #include <string>
 6 #include <math.h>
 7 #include <stdlib.h>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <map>
12 #include <list>
13 #include <iomanip>
14 #include <vector>
15 #pragma comment(linker, "/STACK:1024000000,1024000000")
16 #pragma warning(disable:4786)
17 
18 using namespace std;
19 
20 const int INF = 0x3f3f3f3f;
21 const int MAX = 10000 + 10;
22 const double eps = 1e-8;
23 const double PI = acos(-1.0);
24 
25 int main()
26 {
27     float a , b;
28     while(~scanf("%f %f", &a , &b))
29     {
30         if(fabs(a - b) <= eps)
31             printf("yes\n");
32         else
33             printf("no\n");
34     }
35     return 0;
36 }
View Code

 

相关文章: