diff --git a/du4/program b/du4/program index 5f7e82c..dce0973 100755 Binary files a/du4/program and b/du4/program differ diff --git a/du4/program.c b/du4/program.c index 9f232eb..71636b7 100644 --- a/du4/program.c +++ b/du4/program.c @@ -1,54 +1,57 @@ #include -#include -int main () -{ - int c, vysledok, i = 0; - int b[99]; - bool first = true; - bool second = false; + +int main (){ + char riadok[999]; + char *endptr = NULL; + char need; + int i, a, vysledok = 0; + float c[99]; while(1){ - c = getchar(); - if(c == ' ' || c == '+' || c == '\n' || c == '-' || c == '/' || c == '*' || c == '='){ - 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{ - c = 0; - int r = scanf("%d",&c); - b[i++] = c; - } + char* r = fgets(riadok,999,stdin); + riadok[i++] = *r; + if(*r == '\n') + break; } - if(first == true && second == true) - vysledok = b[0] + b[1]; - else if(first == false && second == false) - vysledok = b[0] - b[1]; - else if(first == true && second == false) - vysledok = b[0] / b[1]; - else if(first == false && second == true) - vysledok = b[0] * b[1]; - if(vysledok == b[2]) + int j = 0; + do{ + if(riadok[j] == ' '){ + j++; + continue; + }else if(riadok[j] == '+'){ + need = riadok[j]; + j++; + continue; + }else if(riadok[i] == '/'){ + need = riadok[j]; + j++; + continue; + }else if(riadok[i] == '-'){ + need = riadok[j]; + j++; + 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++; + continue; + }else{ + float v = strtod(riadok,&endptr); + c[a] = v; + a = a + 1; + } + }while(j < i); + if(vysledok == c[2]) printf("OK\n"); else printf("ZLE\n"); - return 0; } diff --git a/du4/test b/du4/test index db023eb..406980f 100755 Binary files a/du4/test and b/du4/test differ diff --git a/du4/test.c b/du4/test.c index 66d3268..a70c42e 100644 --- a/du4/test.c +++ b/du4/test.c @@ -1,57 +1,17 @@ #include -#include -int main () -{ - int c, vysledok, i = 0; - int b[99]; - bool first = true; - bool second = false; +int main(){ + char riadok[555]; + int i, j = 0; while(1){ - 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{ - if(i == 2) - break; - c = 0; - int r = scanf("%d",&c); - b[i++] = c; - } + riadok[i] = getchar(); + if(riadok[i] == '\n') + break; + else + i++; } - if(first == true && second == true) - vysledok = b[0] + b[1]; - else if(first == false && second == false) - vysledok = b[0] - b[1]; - else if(first == true && second == false) - vysledok = b[0] / b[1]; - else if(first == false && second == true) - vysledok = b[0] * b[1]; - if(vysledok == b[2]) - printf("OK\n"); - else - printf("ZLE\n"); - return 0; + do{ + printf("%c\n", riadok[j]); + j++; + }while(j < i - 2); }