pvjc22/du4/program.c

58 lines
987 B
C
Raw Normal View History

2022-03-30 20:03:13 +00:00
#include <stdio.h>
2022-03-30 21:36:37 +00:00
int main (){
char riadok[999];
char *endptr = NULL;
char need;
int i, a, vysledok = 0;
float c[99];
2022-03-30 20:03:13 +00:00
while(1){
2022-03-30 21:36:37 +00:00
char* r = fgets(riadok,999,stdin);
riadok[i++] = *r;
if(*r == '\n')
break;
}
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;
2022-03-30 20:03:13 +00:00
}else{
2022-03-30 21:36:37 +00:00
float v = strtod(riadok,&endptr);
c[a] = v;
a = a + 1;
2022-03-30 20:03:13 +00:00
}
2022-03-30 21:36:37 +00:00
}while(j < i);
if(vysledok == c[2])
2022-03-30 20:03:13 +00:00
printf("OK\n");
else
printf("ZLE\n");
2022-03-30 20:51:49 +00:00
}