Advertisement
palmerstone

Untitled

Jul 16th, 2011
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cerrno>
  4. #define MAX_LONG 0x7fffffff
  5.  
  6. int main() {
  7. #ifndef ONLINE_JUDGE
  8. freopen("sample.txt", "r", stdin);
  9. #endif
  10. char l[512], *p;
  11. int a, b;
  12. char op, ov;
  13. while ((p = gets(l)) != NULL) {
  14. ov = 0;
  15. puts(l);
  16. a = strtol(p, &p, 10);
  17. if (errno == ERANGE) fputs("first number too big\n", stdout), ov = 1, errno = 0;
  18. op = *(++p);
  19. b = strtol(p + 1, NULL, 10);
  20. if (errno == ERANGE) fputs("second number too big\n", stdout), ov = 1, errno = 0;
  21. if (ov) {
  22. if (op == '+' || (a && b)) fputs("result too big\n", stdout);
  23. } else {
  24. if ((op == '+' && a + b < 0) || (op == '*' && (long long) a * b > MAX_LONG)) fputs("result too big\n", stdout);
  25. }
  26.  
  27. }
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement