From bd48c9ea21e9bf712527247dfa98f74f55076fa5 Mon Sep 17 00:00:00 2001 From: Yaroslav Orlianskyi Date: Wed, 30 Mar 2022 20:46:14 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'du4/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du4/program.c | 79 ++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/du4/program.c b/du4/program.c index 655ee97..cdffea0 100644 --- a/du4/program.c +++ b/du4/program.c @@ -1,55 +1,56 @@ #include #include - -int main(){ - int c[2]; - int a = 0; - int vysledok; - char riadok[999]; - char *endptr = NULL; +int main () +{ + int c, vysledok, i = 0; + int b[99]; bool first = true; bool second = false; while(1){ - char* r = fgets(riadok,999,stdin); - if(*r == '\n'){ - break; - }else if(*r == ' ') - continue; - else if(*r == '+'){ - first = true; - second = true;; - continue; - }else if(*r == '-'){ - first = false; - second = false; - continue; - }else if(*r == '/'){ - first = true; - second = false; - continue; - }else if(*r == '*'){ - first = false; - second = true; - continue; + c = getchar(); + if(c <= 255 && c >= 0){ + if(c == '\n'){ + break; + }else if(c == ' '){ + continue; + }else if(c == '='){ + continue; + }else if(c == '+'){ + first = true; + second = true; + continue; + }else if(c == '-'){ + first = false; + second = false; + continue; + }else if(c == '/'){ + first = true; + second = false; + continue; + }else if(c == '*'){ + first = false; + second = true; + continue; + } }else{ - int v = strtod(riadok,&endptr); - c[a] = v; - printf("%d, %d\n", v, c[a]; - a++; - continue; + if(i == 2) + break; + c = 0; + int r = scanf("%d",&c); + b[i++] = c; } } if(first == true && second == true) - vysledok = c[0] + c[1]; + vysledok = b[0] + b[1]; else if(first == false && second == false) - vysledok = c[0] - c[1]; + vysledok = b[0] - b[1]; else if(first == true && second == false) - vysledok = c[0] / c[1]; + vysledok = b[0] / b[1]; else if(first == false && second == true) - vysledok = c[0] * c[1]; - if(vysledok == c[2]) + vysledok = b[0] * b[1]; + if(vysledok == b[2]) printf("OK\n"); else printf("ZLE\n"); return 0; -} +} \ No newline at end of file