1
0

rcmp9.cpp 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "testlib.h"
  2. #include <cmath>
  3. using namespace std;
  4. #define EPS 1E-9
  5. string ending(int x)
  6. {
  7. x %= 100;
  8. if (x / 10 == 1)
  9. return "th";
  10. if (x % 10 == 1)
  11. return "st";
  12. if (x % 10 == 2)
  13. return "nd";
  14. if (x % 10 == 3)
  15. return "rd";
  16. return "th";
  17. }
  18. int main(int argc, char * argv[])
  19. {
  20. setName("compare two sequences of doubles, max absolute or relative error = %.10lf", EPS);
  21. registerTestlibCmd(argc, argv);
  22. int n = 0;
  23. double j, p;
  24. while (!ans.seekEof())
  25. {
  26. n++;
  27. j = ans.readDouble();
  28. p = ouf.readDouble();
  29. if (!doubleCompare(j, p, EPS))
  30. quitf(_wa, "%d%s numbers differ - expected: '%.10lf', found: '%.10lf', error = '%.10lf'", n, ending(n).c_str(), j, p, doubleDelta(j, p));
  31. }
  32. if (n == 1)
  33. quitf(_ok, "found '%.10lf', expected '%.10lf', error '%.10lf'", p, j, doubleDelta(j, p));
  34. quitf(_ok, "%d numbers", n);
  35. }