47 lines
1.1 KiB
C
47 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include <math.h>
|
|
#include <string.h>
|
|
|
|
int main() {
|
|
char line[256];
|
|
|
|
while (fgets(line, sizeof(line), stdin) != NULL) {
|
|
if (line[0] == '\n' || line[0] == '\r') break;
|
|
|
|
double a, b, result;
|
|
char op;
|
|
char eq;
|
|
char extra;
|
|
|
|
int n = 0;
|
|
int parsed = sscanf(line, " %lf %c %lf %c %lf %c%n", &a, &op, &b, &eq, &result, &extra, &n);
|
|
|
|
if (parsed != 5 || eq != '=') {
|
|
printf("CHYBA\n");
|
|
continue;
|
|
}
|
|
|
|
if (op != '+' && op != '-' && op != '*' && op != '/') {
|
|
printf("CHYBA\n");
|
|
continue;
|
|
}
|
|
|
|
double actual;
|
|
if (op == '+') actual = a + b;
|
|
else if (op == '-') actual = a - b;
|
|
else if (op == '*') actual = a * b;
|
|
else actual = a / b;
|
|
|
|
double rounded_actual = round(actual * 100.0) / 100.0;
|
|
double rounded_result = round(result * 100.0) / 100.0;
|
|
|
|
if (fabs(rounded_actual - rounded_result) < 1e-9) {
|
|
printf("OK\n");
|
|
} else {
|
|
printf("ZLE\n");
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|