diff --git a/du4/program.c b/du4/program.c index 71636b7..b4daee9 100644 --- a/du4/program.c +++ b/du4/program.c @@ -1,57 +1,54 @@ #include +#include -int main (){ +int main(){ + int c[2]; + int a, i = 0; + int vysledok; char riadok[999]; char *endptr = NULL; - char need; - int i, a, vysledok = 0; - float c[99]; + bool first = true; + bool second = false; while(1){ + a++; char* r = fgets(riadok,999,stdin); - riadok[i++] = *r; - if(*r == '\n') + if(*r == '\n'){ break; - } - int j = 0; - do{ - if(riadok[j] == ' '){ - j++; + }else if(*r == ' ') continue; - }else if(riadok[j] == '+'){ - need = riadok[j]; - j++; + else if(*r == '+'){ + first = true; + second = true;; continue; - }else if(riadok[i] == '/'){ - need = riadok[j]; - j++; + }else if(*r == '-'){ + first = false; + second = false; continue; - }else if(riadok[i] == '-'){ - need = riadok[j]; - j++; + }else if(*r == '/'){ + first = true; + second = false; continue; - }else if(riadok[j] == '*'){ - need = riadok[j]; - j++; - continue; - }else if(riadok[j] == '='){ - if(need == '+') - vysledok = c[0] + c[1]; - else if(need == '-') - vysledok = c[0] - c[1]; - else if(need == '/') - vysledok = c[0] / c[1]; - else if(need == '*') - vysledok = c[0] * c[1]; - j++; + }else if(*r == '*'){ + first = false; + second = true; continue; }else{ float v = strtod(riadok,&endptr); - c[a] = v; - a = a + 1; + c[i++] = v; + continue; } - }while(j < i); + } + if(first == true && second == true) + vysledok = c[0] + c[1]; + else if(first == false && second == false) + vysledok = c[0] - c[1]; + else if(first == true && second == false) + vysledok = c[0] / c[1]; + else if(first == false && second == true) + vysledok = c[0] * c[1]; if(vysledok == c[2]) printf("OK\n"); else printf("ZLE\n"); -} + return 0; +} \ No newline at end of file