hcmp.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "testlib.h"
  2. #include <string>
  3. using namespace std;
  4. string part(const string& s)
  5. {
  6. if (s.length() <= 128)
  7. return s;
  8. else
  9. return s.substr(0, 64) + "..." + s.substr(s.length() - 64, 64);
  10. }
  11. bool isNumeric(string p)
  12. {
  13. bool minus = false;
  14. if (p[0] == '-')
  15. minus = true,
  16. p = p.substr(1);
  17. for (int i = 0; i < p.length(); i++)
  18. if (p[i] < '0' || p[i] > '9')
  19. return false;
  20. if (minus)
  21. return (p.length() > 0 && (p.length() == 1 || p[0] != '0')) && (p.length() > 1 || p[0] != '0');
  22. else
  23. return p.length() > 0 && (p.length() == 1 || p[0] != '0');
  24. }
  25. int main(int argc, char * argv[])
  26. {
  27. setName("compare two signed huge integers");
  28. registerTestlibCmd(argc, argv);
  29. string ja = ans.readWord();
  30. string pa = ouf.readWord();
  31. if (!isNumeric(ja))
  32. quitf(_fail, "%s is not valid integer", part(ja).c_str());
  33. if (!ans.seekEof())
  34. quitf(_fail, "expected exactly one token in the answer file");
  35. if (!isNumeric(pa))
  36. quitf(_pe, "%s is not valid integer", part(pa).c_str());
  37. if (ja != pa)
  38. quitf(_wa, "expected %s, found %s", part(ja).c_str(), part(pa).c_str());
  39. quitf(_ok, "answer is %s", part(ja).c_str());
  40. }