ncmp.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "testlib.h"
  2. using namespace std;
  3. int main(int argc, char *argv[]) {
  4. setName("compare ordered sequences of signed int%d numbers", 8 * int(sizeof(long long)));
  5. registerTestlibCmd(argc, argv);
  6. int n = 0;
  7. string firstElems;
  8. while (!ans.seekEof() && !ouf.seekEof()) {
  9. n++;
  10. long long j = ans.readLong();
  11. long long p = ouf.readLong();
  12. if (j != p)
  13. quitf(_wa, "%d%s numbers differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(),
  14. vtos(j).c_str(), vtos(p).c_str());
  15. else if (n <= 5) {
  16. if (firstElems.length() > 0)
  17. firstElems += " ";
  18. firstElems += vtos(j);
  19. }
  20. }
  21. int extraInAnsCount = 0;
  22. while (!ans.seekEof()) {
  23. ans.readLong();
  24. extraInAnsCount++;
  25. }
  26. int extraInOufCount = 0;
  27. while (!ouf.seekEof()) {
  28. ouf.readLong();
  29. extraInOufCount++;
  30. }
  31. if (extraInAnsCount > 0)
  32. quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements",
  33. n + extraInAnsCount, n);
  34. if (extraInOufCount > 0)
  35. quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements",
  36. n + extraInOufCount, n);
  37. if (n <= 5)
  38. quitf(_ok, "%d number(s): \"%s\"", n, compress(firstElems).c_str());
  39. else
  40. quitf(_ok, "%d numbers", n);
  41. }