1
0

rncmp.cpp 814 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "testlib.h"
  2. #include <cmath>
  3. using namespace std;
  4. #define EPS 1.5E-5
  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, maximal absolute error = %.10lf", EPS);
  21. registerTestlibCmd(argc, argv);
  22. int n = 0;
  23. while (!ans.seekEof())
  24. {
  25. n++;
  26. double j = ans.readDouble();
  27. double p = ouf.readDouble();
  28. if (fabs(j - p) > EPS)
  29. quitf(_wa, "%d%s numbers differ - expected: '%.10lf', found: '%.10lf'", n, ending(n).c_str(), j, p);
  30. }
  31. quitf(_ok, "%d numbers", n);
  32. }