fix s pismenami
This commit is contained in:
parent
fd681e9a86
commit
4611c10605
@ -17,7 +17,8 @@ int main() {
|
||||
int eq_index = 0;
|
||||
int index = 0;
|
||||
while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
||||
if (buffer[0] == '\n') break;
|
||||
int error = 0;
|
||||
if (buffer[0] == '\n') break;
|
||||
index = 0;
|
||||
eq_index = 0;
|
||||
int eq_operand_length = 0;
|
||||
@ -27,6 +28,12 @@ int main() {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
if (isalpha(buffer[index]) && !error) {
|
||||
error = 1;
|
||||
strcpy(output[output_length], "CHYBA");
|
||||
output_length++;
|
||||
|
||||
}
|
||||
if (isdigit(buffer[index]) || (buffer[index] == '.' && eq_operand_length > 0 && isdigit(buffer[index + 1])) || (buffer[index] == '-' && (eq_operand_length == 0 || strchr("+-*/=", buffer[index - 1])))) {
|
||||
equation[eq_index][eq_operand_length] = buffer[index];
|
||||
eq_operand_length++;
|
||||
@ -47,13 +54,13 @@ int main() {
|
||||
equation[eq_index][eq_operand_length] = '\0';
|
||||
eq_index++;
|
||||
}
|
||||
|
||||
float total = 0.0;
|
||||
char last_operator = '+';
|
||||
int sign = 0;
|
||||
int n_of_signs = 0;
|
||||
char operators[6] = "+-=*/";
|
||||
for (int i=0;i<eq_index;i++) {
|
||||
if (!error) {
|
||||
for (int i=0;i<eq_index;i++) {
|
||||
n_of_signs = 0;
|
||||
for (int l=0; l<5;l++) {
|
||||
if (strchr(equation[i], operators[l]) != NULL) {
|
||||
@ -78,7 +85,6 @@ int main() {
|
||||
total = divided(total, atof(equation[i]));
|
||||
break;
|
||||
case '=':
|
||||
//total = round(total * 100) / 100;
|
||||
if (fabs((round(total * 100) / 100) - atof(equation[i])) < 1e-6) {
|
||||
strcpy(output[output_length], "OK");
|
||||
output_length++;
|
||||
@ -98,6 +104,7 @@ int main() {
|
||||
}
|
||||
sign = !sign;
|
||||
}
|
||||
}
|
||||
memset(equation, 0, sizeof(equation));
|
||||
//printf("%f - %f\n",total, (round(total * 100) / 100));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user