Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cerrno>
- #define MAX_LONG 0x7fffffff
- int main() {
- #ifndef ONLINE_JUDGE
- freopen("sample.txt", "r", stdin);
- #endif
- char l[512], *p;
- int a, b;
- char op, ov;
- while ((p = gets(l)) != NULL) {
- ov = 0;
- puts(l);
- a = strtol(p, &p, 10);
- if (errno == ERANGE) fputs("first number too big\n", stdout), ov = 1, errno = 0;
- op = *(++p);
- b = strtol(p + 1, NULL, 10);
- if (errno == ERANGE) fputs("second number too big\n", stdout), ov = 1, errno = 0;
- if (ov) {
- if (op == '+' || (a && b)) fputs("result too big\n", stdout);
- } else {
- if ((op == '+' && a + b < 0) || (op == '*' && (long long) a * b > MAX_LONG)) fputs("result too big\n", stdout);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement