This commit is contained in:
Yaroslav Orlianskyi 2022-03-30 23:43:10 +02:00
parent 6f81912e02
commit d09136c0cb
2 changed files with 13 additions and 19 deletions

Binary file not shown.

View File

@ -1,14 +1,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
int main(){ int main(){
int c[2]; int c[999];
int a, i = 0; int a, i = 0;
int vysledok; int vysledok;
char riadok[999]; char riadok[999];
char *endptr = NULL; char *endptr = NULL;
bool first = true; char need;
bool second = false;
while(1){ while(1){
a++; a++;
char* r = fgets(riadok,999,stdin); char* r = fgets(riadok,999,stdin);
@ -17,36 +15,32 @@ int main(){
}else if(*r == ' ') }else if(*r == ' ')
continue; continue;
else if(*r == '+'){ else if(*r == '+'){
first = true; need = *r;
second = true;;
continue; continue;
}else if(*r == '-'){ }else if(*r == '-'){
first = false; need = *r;
second = false;
continue; continue;
}else if(*r == '/'){ }else if(*r == '/'){
first = true; need = *r;
second = false;
continue; continue;
}else if(*r == '*'){ }else if(*r == '*'){
first = false; need = *r;
second = true;
continue; continue;
}else{ }else{
float v = strtod(riadok,&endptr); int v = strtod(riadok,&endptr);
c[i++] = v; c[i++] = v;
continue; continue;
} }
} }
if(first == true && second == true) if(need == '+')
vysledok = c[0] + c[1]; vysledok = c[0] + c[1];
else if(first == false && second == false) else if(need == '-')
vysledok = c[0] - c[1]; vysledok = c[0] - c[1];
else if(first == true && second == false) else if(need == '/')
vysledok = c[0] / c[1]; vysledok = c[0] / c[1];
else if(first == false && second == true) else if(need == '*')
vysledok = c[0] * c[1]; vysledok = c[0] * c[1];
if(vysledok == c[2]) if(vysledok == c[i])
printf("OK\n"); printf("OK\n");
else else
printf("ZLE\n"); printf("ZLE\n");