ncmp.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. string ltoa(long long n)
  18. {
  19. stringstream ss;
  20. ss << n;
  21. string result;
  22. ss >> result;
  23. return result;
  24. }
  25. int main(int argc, char * argv[])
  26. {
  27. setName("compare ordered sequences of signed int%d numbers", 8 * sizeof(long long));
  28. registerTestlibCmd(argc, argv);
  29. int n = 0;
  30. string firstElems;
  31. while (!ans.seekEof())
  32. {
  33. n++;
  34. long long j = ans.readLong();
  35. long long p = ouf.readLong();
  36. if (j != p)
  37. quitf(_wa, "%d%s numbers differ - expected: '%s', found: '%s'", n, ending(n).c_str(), ltoa(j).c_str(), ltoa(p).c_str());
  38. else
  39. if (n <= 5)
  40. {
  41. if (firstElems.length() > 0)
  42. firstElems += " ";
  43. firstElems += ltoa(j);
  44. }
  45. }
  46. if (n <= 5)
  47. {
  48. quitf(_ok, "%d number(s): \"%s\"", n, firstElems.c_str());
  49. }
  50. else
  51. quitf(_ok, "%d numbers", n);
  52. }