hcmp.cpp 1.2 KB

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