From e7133897762efc26864fee2c30ab0aa2d2d5fa9d Mon Sep 17 00:00:00 2001 From: Yevhen Kozirovskyi Date: Thu, 17 Oct 2024 16:36:28 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20cv3/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 9dbb83a..1f1e19a 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -2,13 +2,10 @@ #include #include -#define MAX_RAZMER 100 - +#define MAX_RAZMER 10 typedef struct { - double chisla[MAX_RAZMER]; - int vershina; } StEk; @@ -19,13 +16,13 @@ void inicStEk(StEk* stek) { int isEmpty(StEk* stek) { return stek->vershina == 0; } -int isFull(StEk* stek) { +int isFull(StEk* stek) { return stek->vershina == MAX_RAZMER; } void push(StEk* stek, double chislo) { - if(isFull(stek)) { + if (isFull(stek)) { printf("no input\n"); exit(1); } @@ -33,9 +30,8 @@ void push(StEk* stek, double chislo) { stek->vershina++; } - double pop(StEk* stek) { - if(isEmpty(stek)) { + if (isEmpty(stek)) { printf("no input\n"); exit(1); } @@ -43,58 +39,57 @@ double pop(StEk* stek) { } int main() { - StEk stek; inicStEk(&stek); char bufer[256]; - while(fgets(bufer, sizeof(bufer), stdin)) { + while (fgets(bufer, sizeof(bufer), stdin)) { char* konec; double chislo = strtod(bufer, &konec); - if(*konec == '\n' && *bufer != '\n' && *bufer != ' ') { + if (*konec == '\n' && *bufer != '\n' && *bufer != ' ') { push(&stek, chislo); - } else if(strcmp(konec, "+\n") == 0) { - if(isEmpty(&stek)) { + } else if (strcmp(konec, "+\n") == 0) { + if (isEmpty(&stek)) { printf("no input\n"); exit(1); } double b = pop(&stek); - if(isEmpty(&stek)) { + if (isEmpty(&stek)) { printf("no input\n"); exit(1); } double a = pop(&stek); push(&stek, a + b); - } else if(strcmp(konec, "-\n") == 0) { - if(isEmpty(&stek)) { + } else if (strcmp(konec, "-\n") == 0) { + if (isEmpty(&stek)) { printf("no input\n"); exit(1); } double b = pop(&stek); - if(isEmpty(&stek)) { + if (isEmpty(&stek)) { printf("no input\n"); exit(1); } double a = pop(&stek); push(&stek, a - b); - } else if(strcmp(konec, "*\n") == 0) { - if(isEmpty(&stek)) { + } else if (strcmp(konec, "*\n") == 0) { + if (isEmpty(&stek)) { printf("no input\n"); exit(1); } double b = pop(&stek); - if(isEmpty(&stek)) { + if (isEmpty(&stek)) { printf("no input\n"); exit(1); } double a = pop(&stek); push(&stek, a * b); - } else if(strcmp(konec, "/\n") == 0) { - if(isEmpty(&stek)) { + } else if (strcmp(konec, "/\n") == 0) { + if (isEmpty(&stek)) { printf("no input\n"); exit(1); } double b = pop(&stek); - if(isEmpty(&stek)) { + if (isEmpty(&stek)) { printf("no input\n"); exit(1); } @@ -104,7 +99,7 @@ int main() { printf("no input\n"); exit(1); } - for(int i = 0; i < stek.vershina; i++) { + for (int i = 0; i < stek.vershina; i++) { printf("%.2lf ", stek.chisla[i]); } printf("\n");