This commit is contained in:
Deinerovych 2024-10-16 10:15:24 +02:00
parent 6d18b78144
commit 5b9d8d433b

View File

@ -61,6 +61,7 @@ int main() {
char *pend; char *pend;
stack_top = -1; stack_top = -1;
bool first_output = true; bool first_output = true;
bool operation_successful = true;
while (fgets(arr, 50, stdin)) { while (fgets(arr, 50, stdin)) {
if (arr[0] == '\n' || arr[0] == EOF) { if (arr[0] == '\n' || arr[0] == EOF) {
@ -75,6 +76,7 @@ int main() {
} }
printf("%.2f", number); printf("%.2f", number);
first_output = false; first_output = false;
operation_successful = true;
} }
else if (is_operation(arr)) { else if (is_operation(arr)) {
if (stack_top < 1) { if (stack_top < 1) {
@ -83,6 +85,7 @@ int main() {
} }
printf("no input"); printf("no input");
first_output = false; first_output = false;
operation_successful = false;
continue; continue;
} }
@ -96,6 +99,7 @@ int main() {
} }
printf("%.2f", result); printf("%.2f", result);
first_output = false; first_output = false;
operation_successful = true;
} }
else { else {
if (!first_output) { if (!first_output) {
@ -103,16 +107,17 @@ int main() {
} }
printf("no input"); printf("no input");
first_output = false; first_output = false;
operation_successful = false;
continue; continue;
} }
} }
if (stack_top == 0) { if (operation_successful && stack_top == 0) {
if (!first_output) { if (!first_output) {
printf(" "); printf(" ");
} }
printf("%.2f", pop()); printf("%.2f", pop());
} else { } else if (!operation_successful) {
if (!first_output) { if (!first_output) {
printf(" "); printf(" ");
} }