85 lines
1.7 KiB
C
85 lines
1.7 KiB
C
#include<math.h>
|
|
#include<stdio.h>
|
|
#include<string.h>
|
|
#include<stdlib.h>
|
|
|
|
int main(){
|
|
int ch=getchar();
|
|
char priklad[300];
|
|
int count=0;
|
|
|
|
for(int idx=0;1;idx++){
|
|
priklad[idx]=ch;
|
|
if(ch=='\n'){
|
|
count++;
|
|
}
|
|
ch=getchar();
|
|
if((priklad[idx]=='\n'&&ch=='\n')||ch==EOF){
|
|
break;
|
|
}
|
|
}
|
|
|
|
char *start=priklad, *end=NULL;
|
|
|
|
for(int c=0;c<count;c++){
|
|
int skip=0;
|
|
for(int idx=0;start[idx]!='\n';idx++){
|
|
if((start[idx]<'0'||start[idx]>'9')&&start[idx]!=' '&&start[idx]!='='&&start[idx]!='+'&&start[idx]!='-'&&start[idx]!='*'&&start[idx]!='/'&&start[idx]!='.'){
|
|
skip=1;
|
|
printf("CHYBA\n");
|
|
break;
|
|
}
|
|
}
|
|
if(skip==1){
|
|
continue;
|
|
}
|
|
float num1=strtof(start,&end);
|
|
if(end==start){
|
|
printf("KONIEC\n");
|
|
}
|
|
while((*start)!='+'&&(*start)!='-'&&(*start)!='/'&&(*start)!='*'){
|
|
start++;
|
|
}
|
|
char znak=(*start);
|
|
start++;
|
|
|
|
float num2=strtof(start,&end);
|
|
start=end;
|
|
while(((*start)<'0'||(*start)>'9')&&(*start)!='-'){
|
|
start++;
|
|
}
|
|
|
|
float vysledok2=strtof(start,&end);
|
|
start=end;
|
|
//printf("%f\n",vysledok2);
|
|
float vysledok=0;
|
|
|
|
/*if(num2==0&&znak=='/'){
|
|
printf("CHYBA\n");
|
|
}*/
|
|
if(znak=='-'){
|
|
vysledok=num1-num2;
|
|
}
|
|
else if(znak=='+'){
|
|
vysledok=num1+num2;
|
|
}
|
|
else if(znak=='*'){
|
|
vysledok=num1*num2;
|
|
}
|
|
else if(znak=='/'){
|
|
vysledok=num1/num2;
|
|
}
|
|
vysledok=(round(vysledok*100))/100;
|
|
if (vysledok2-vysledok < 0.001 && vysledok2-vysledok > -0.001){
|
|
printf("OK\n");
|
|
}
|
|
else{
|
|
printf("ZLE\n");
|
|
}
|
|
}
|
|
// printf("%.3f\n", vysledok);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|