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