Test instructions: For a given 12 numbers, the average is calculated.
Analysis: This problem is the precision control problems, if the control accuracy, the best way is to use the integral type.
The code is as follows:
#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream > #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector > #include <map> #include <cctype>using namespace std; typedef long Long Ll;typedef pair<int, int> p;c onst int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = 2e5 + 5;const int D R[] = {0, 0,-1, 1};const int dc[] = {-1, 1, 0, 0};int N, m;inline bool is_in (int r, int c) {return R >= 0 && ; R < n && C >= 0 && C < m;} int A[maxn];int Main () {int T; Cin >> T; while (t--) {double sum = 0; Double X; for (int i = 0; i <; ++i) {cin >> x; sum + = x; } int ans = (int) round (sum * 100.0/12.0); printf ("$"); printf ("%d", ans/100); int y = ans% 100; if (!y); else{ printf (".%d", Y/10); y = y% 10; if (!y); else printf ("%d", y%10); } printf ("\ n"); } return 0;}
HDU 4493 Tutor (Control accuracy)