ncmp.cpp 1.5 KB

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