ncmp.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "testlib.h"
  2. #include <sstream>
  3. using namespace std;
  4. string ending(long long x)
  5. {
  6. x %= 100;
  7. if (x / 10 == 1)
  8. return "th";
  9. if (x % 10 == 1)
  10. return "st";
  11. if (x % 10 == 2)
  12. return "nd";
  13. if (x % 10 == 3)
  14. return "rd";
  15. return "th";
  16. }
  17. int main(int argc, char * argv[])
  18. {
  19. setName("compare ordered sequences of signed int%d numbers", 8 * sizeof(long long));
  20. registerTestlibCmd(argc, argv);
  21. int n = 0;
  22. string firstElems;
  23. while (!ans.seekEof() && !ouf.seekEof())
  24. {
  25. n++;
  26. long long j = ans.readLong();
  27. long long p = ouf.readLong();
  28. if (j != p)
  29. quitf(_wa, "%d%s numbers differ - expected: '%s', found: '%s'", n, ending(n).c_str(), ltoa(j).c_str(), ltoa(p).c_str());
  30. else
  31. if (n <= 5)
  32. {
  33. if (firstElems.length() > 0)
  34. firstElems += " ";
  35. firstElems += vtos(j);
  36. }
  37. }
  38. int extraInAnsCount = 0;
  39. while (!ans.seekEof())
  40. {
  41. ans.readLong();
  42. extraInAnsCount++;
  43. }
  44. int extraInOufCount = 0;
  45. while (!ouf.seekEof())
  46. {
  47. ouf.readLong();
  48. extraInOufCount++;
  49. }
  50. quitif(extraInAnsCount > 0, _wa, "Answer contains longer sequence [length = %d], but output contains %d elements",
  51. n + extraInAnsCount, n);
  52. quitif(extraInOufCount > 0, _wa, "Output contains longer sequence [length = %d], but answer contains %d elements",
  53. n + extraInOufCount, n);
  54. if (n <= 5)
  55. quitf(_ok, "%d number(s): \"%s\"", n, firstElems.c_str());
  56. else
  57. quitf(_ok, "%d numbers", n);
  58. }