Untitled
unknown
c_cpp
16 days ago
1.5 kB
2
Indexable
Never
#include <stdio.h> #include <math.h> int main() { char operator; long long result, operand; if (scanf("%llx", &result) != 1) { printf("Invalid input.\n"); return 1; } while (1) { operator = getchar(); if (operator == '=') { break; } if (scanf("%llx", &operand) != 1) { printf("Invalid input.\n"); return 1; } switch (operator) { case '+': result += operand; break; case '-': result -= operand; break; case '*': result *= operand; break; case '/': if (operand == 0) { printf("You can't divide with zero!\n"); return 1; } result /= operand; break; case '^': result = pow(result, operand); break; default: printf("Invalid operator: %c\n", operator); return 1; } } long long expected; if (scanf("%llx", &expected) != 1) { printf("Invalid input.\n"); return 1; } if (result == expected) { printf("Correct!\n"); } else { printf("BaBaBa, It's wrong.\n%llx\n", result); } return 0; }