1
0

wcmp.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "testlib.h"
  2. using namespace std;
  3. string ending(int x)
  4. {
  5. x %= 100;
  6. if (x / 10 == 1)
  7. return "th";
  8. if (x % 10 == 1)
  9. return "st";
  10. if (x % 10 == 2)
  11. return "nd";
  12. if (x % 10 == 3)
  13. return "rd";
  14. return "th";
  15. }
  16. int main(int argc, char * argv[])
  17. {
  18. setName("compare sequences of tokens");
  19. registerTestlibCmd(argc, argv);
  20. std::string strAnswer;
  21. int n = 0;
  22. while (!ans.seekEof() && !ouf.seekEof())
  23. {
  24. n++;
  25. std::string j = ans.readWord();
  26. std::string p = ouf.readWord();
  27. strAnswer = p;
  28. quitif(j != p, _wa, "%d%s words differ - expected: '%s', found: '%s'",
  29. n, ending(n).c_str(), __testlib_part(j).c_str(), __testlib_part(p).c_str());
  30. }
  31. if (ans.seekEof() && ouf.seekEof())
  32. {
  33. if (n == 1)
  34. quitf(_ok, "%s", __testlib_part(strAnswer).c_str());
  35. else
  36. quitf(_ok, "%d words", n);
  37. }
  38. else
  39. {
  40. if (ans.seekEof())
  41. quitf(_wa, "Participant output contains extra tokens");
  42. else
  43. quitf(_wa, "Unexpected EOF in the participants output");
  44. }
  45. }