uncmp.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "testlib.h"
  2. #include <vector>
  3. using namespace std;
  4. int main(int argc, char *argv[]) {
  5. setName("compare unordered sequences of signed int%u numbers", int(8 * sizeof(long long)));
  6. registerTestlibCmd(argc, argv);
  7. vector<long long> ja, pa;
  8. while (!ans.seekEof())
  9. ja.push_back(ans.readLong());
  10. while (!ouf.seekEof())
  11. pa.push_back(ouf.readLong());
  12. if (ja.size() != pa.size())
  13. quitf(_wa, "Expected %u elements, but %u found", (unsigned int) (ja.size()), (unsigned int) (pa.size()));
  14. sort(ja.begin(), ja.end());
  15. sort(pa.begin(), pa.end());
  16. if (ja != pa)
  17. quitf(_wa, "Expected sequence and output are different (as unordered sequences) [size=%u]",
  18. (unsigned int) (ja.size()));
  19. string message;
  20. if (ja.size() != 1)
  21. if (ja.empty())
  22. message = "empty sequence";
  23. else
  24. message = vtos(ja.size()) + " numbers (in increasing order):";
  25. else
  26. message = vtos(ja.size()) + " number:";
  27. if (ja.size() <= 5)
  28. for (int i = 0; i < min(int(ja.size()), 5); i++)
  29. message += " " + vtos(ja[i]);
  30. else {
  31. for (int i = 0; i < 2; i++)
  32. message += " " + vtos(ja[i]);
  33. message += " ...";
  34. for (int i = 0; i < 2; i++)
  35. message += " " + vtos(ja[ja.size() - 2 + i]);
  36. }
  37. quitf(_ok, "%s", message.c_str());
  38. }