1
0

ncmp.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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() && !ouf.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. int extraInAnsCount = 0;
  47. while (!ans.seekEof())
  48. {
  49. ans.readLong();
  50. extraInAnsCount++;
  51. }
  52. int extraInOufCount = 0;
  53. while (!ouf.seekEof())
  54. {
  55. ouf.readLong();
  56. extraInOufCount++;
  57. }
  58. if (extraInAnsCount > 0)
  59. quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements", n + extraInAnsCount, n);
  60. if (extraInOufCount > 0)
  61. quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements", n + extraInOufCount, n);
  62. if (n <= 5)
  63. {
  64. quitf(_ok, "%d number(s): \"%s\"", n, firstElems.c_str());
  65. }
  66. else
  67. quitf(_ok, "%d numbers", n);
  68. }