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