2020-03-31 10:25:27 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2020-04-02 13:21:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void add(double a, double b, double c,char ac, int result[],int count){
|
|
|
|
float cc=a+b;
|
|
|
|
if(cc==(float)c || a+b==c) result[count]=1;
|
|
|
|
else result[count]=2;
|
2020-04-01 09:33:19 +00:00
|
|
|
}
|
2020-04-02 13:21:51 +00:00
|
|
|
|
2020-04-02 16:01:13 +00:00
|
|
|
void subtr(double a, double b, double c,char ac, int result[],int count){
|
2020-04-02 13:21:51 +00:00
|
|
|
if(a-b==c) result[count]=1;
|
|
|
|
else result[count]=2;
|
2020-04-01 09:33:19 +00:00
|
|
|
}
|
2020-04-02 13:21:51 +00:00
|
|
|
|
2020-04-02 16:01:13 +00:00
|
|
|
void multi(double a, double b, double c,char ac, int result[],int count){
|
2020-04-02 13:21:51 +00:00
|
|
|
if(a*b==c) result[count]=1;
|
|
|
|
else result[count]=2;
|
2020-04-01 09:33:19 +00:00
|
|
|
}
|
2020-04-02 13:21:51 +00:00
|
|
|
|
2020-04-02 16:01:13 +00:00
|
|
|
void divi(double a, double b, double c,char ac, int result[],int count){
|
2020-04-02 13:21:51 +00:00
|
|
|
float cc=a/b;
|
|
|
|
double Cc=(int)((a/b)*100000);
|
2020-04-02 16:08:24 +00:00
|
|
|
if(cc==c || a/b==c || Cc==(int)(c*100000)) result[count]=1;
|
2020-04-02 13:21:51 +00:00
|
|
|
else result[count]=2;
|
2020-03-31 10:25:27 +00:00
|
|
|
}
|
2020-03-31 18:40:15 +00:00
|
|
|
|
2020-04-02 13:21:51 +00:00
|
|
|
|
2020-03-31 10:25:27 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
char *str;
|
2020-04-02 13:21:51 +00:00
|
|
|
int *result;
|
|
|
|
result=(int*)malloc(100);
|
|
|
|
double a,b,c;
|
|
|
|
char ac,el=0;
|
|
|
|
int count=0;
|
|
|
|
int eof;
|
2020-04-03 00:11:45 +00:00
|
|
|
int ro=0;
|
2020-04-02 13:21:51 +00:00
|
|
|
for(;eof!=EOF;count++){
|
2020-04-02 16:01:13 +00:00
|
|
|
eof=0;
|
2020-04-02 19:03:18 +00:00
|
|
|
int k=0;
|
2020-04-02 16:01:13 +00:00
|
|
|
str=(char*)malloc(100);
|
2020-04-02 13:21:51 +00:00
|
|
|
int ind=0;
|
2020-04-02 16:01:13 +00:00
|
|
|
for(int i=0;eof!='\n';i++){
|
|
|
|
eof=getchar();
|
|
|
|
if(eof==EOF) break;
|
2020-04-03 00:07:43 +00:00
|
|
|
if(eof=='='){
|
2020-04-03 00:20:53 +00:00
|
|
|
ro=1;
|
2020-04-03 00:07:43 +00:00
|
|
|
}
|
2020-04-03 00:27:03 +00:00
|
|
|
if(!isdigit(eof) && eof!='.' && eof!=' '){
|
2020-04-02 19:03:18 +00:00
|
|
|
k++;
|
|
|
|
}
|
2020-04-02 16:01:13 +00:00
|
|
|
if(eof!=' '){
|
|
|
|
str[ind]=eof;
|
|
|
|
ind++;
|
2020-04-02 13:21:51 +00:00
|
|
|
}
|
2020-04-03 00:07:43 +00:00
|
|
|
}
|
|
|
|
if(ro==0){
|
2020-04-03 00:20:53 +00:00
|
|
|
printf("CHYBA\n");
|
2020-04-03 00:07:43 +00:00
|
|
|
break;
|
2020-03-31 11:02:27 +00:00
|
|
|
}
|
2020-04-02 16:02:42 +00:00
|
|
|
if(eof==EOF) break;
|
2020-04-02 13:21:51 +00:00
|
|
|
sscanf(str,"%lF%c%lF=%lF ",&a,&ac,&b,&c);
|
2020-04-02 19:03:18 +00:00
|
|
|
free(str);
|
2020-04-02 19:08:56 +00:00
|
|
|
if(k>2){
|
2020-04-02 19:03:18 +00:00
|
|
|
result[count]=3;
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-02 13:21:51 +00:00
|
|
|
switch(ac){
|
|
|
|
case '+':
|
|
|
|
add(a,b,c,ac,result,count);
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
subtr(a,b,c,ac,result,count);
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
multi(a,b,c,ac,result,count);
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
divi(a,b,c,ac,result,count);
|
|
|
|
break;
|
|
|
|
default:
|
2020-04-02 19:03:18 +00:00
|
|
|
result[count]=3;
|
2020-04-02 13:21:51 +00:00
|
|
|
}
|
2020-04-03 00:07:43 +00:00
|
|
|
|
2020-03-31 11:02:27 +00:00
|
|
|
}
|
2020-04-02 13:21:51 +00:00
|
|
|
count--;
|
|
|
|
for(int j=0;j<count;j++){
|
|
|
|
if(result[j]==1) printf("OK\n");
|
|
|
|
if(result[j]==2) printf("ZLE\n");
|
|
|
|
if(result[j]==3) printf("CHYBA\n");
|
|
|
|
}
|
|
|
|
|
2020-03-31 10:25:27 +00:00
|
|
|
return 0;
|
2020-04-03 00:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-03 00:20:53 +00:00
|
|
|
|