diff --git a/du4/program.c b/du4/program.c index 8df203f..d8c943e 100644 --- a/du4/program.c +++ b/du4/program.c @@ -1,144 +1,171 @@ -/* -gcc -Werror -std=c11 -Wall in-out.c -lm -o in-out -lm && ./in-out -*/ -#include -#include -#include -#include -#include +#include -struct res{ - double na,nb,result; - char sign; -}list [10]; +#include -int fill(double*,double*,char *,double *); -double count(const double*,const double *,char); -int aget(double *); -int sget(char *); -int efinde(void); -char checkend(void); +#include -int main(){ - int cond; - char fcond=1; - int i; - for(i=0;fcond!=EOF;i++){ - fcond=checkend(); - if(fcond==EOF) - break; - - cond=aget(&list[i].na); - if(cond<0){ - printf("CHYBA\n"); - return 0;} - cond=sget(&list[i].sign); - if(cond<0){ - printf("CHYBA\n"); - return 0;} - cond=aget(&list[i].nb); - if(cond<0){ - printf("CHYBA\n"); - return 0;} - cond=efinde(); - if(cond<0){ - printf("CHYBA\n"); - return 0;} - cond=aget(&list[i].result); - if(cond<0){ - printf("CHYBA\n"); - return 0;} - if((fcond=checkend())!='\n' && fcond>0){ - printf("CHYBA\n"); - return 0;} - if(fcond==-1) - break; - //printf("%lf %c %lf = %lf\n",list[i].na,list[i].sign,list[i].nb,list[i].result); - } - for(int x=0;x + +char* compactString(char *src,int leng) { + +char *new_str = (char*)calloc(leng+1,sizeof(char)); + +int k=0; + +for(int i=0;i 0 ? +1 : 0; + +} + +int check(char *str){ + +int flag=0; + +char symb[5]="*-+/="; + +for(int i =0;i='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')||str[i]==','){ + +return 0; + +} + +} + +return flag==1?1:0; + +} + +int main() + +{ + +char str[100][100]; + + for(int i =0;fgets(str[i],100,stdin);i++){ + + if(str[i][0]=='\n'){ + + break; + + } + + char *new_str = compactString(str[i],strlen(str[i])); + + double first =-5,second =-5,res=-5; + + char c='E'; + + sscanf(new_str,"%lf%c%lf%*[=]%lf",&first,&c,&second,&res); + + if(c!=43&&c!=42&&c!=45&&c!=47||check(new_str)==0){ + + printf("CHYBA\n"); + + continue; + + } + + double my_res = operation(first,second,c); + + if(compare_percent(res,my_res,0.01)==0){ + + printf("OK\n"); + + } + + else{ + + printf("ZLE\n"); + + } + +} + +return 0; -int aget(double *na){ - char a[30]; - char c; - char *p; - p=a; - while(isspace(c=getchar())); - if(isdigit(c)){ - *(p++)=c; - while(isdigit(c=getchar())|| c=='.') *(p++)=c; - *p='\0'; - *na=atof(a); - }else - return -1; - fseek(stdin,-1,SEEK_CUR); - return 1; -} -int sget(char *sign){ - char c; - while(isspace(c=getchar())); - if(c=='+' || c=='-' || c=='/' || c=='*') - *sign=c; - else - return -1; - return 1; -} -int efinde(void){ - char c; - while(isspace(c=getchar())); - if(c!='=') - return -1; - return 1; } \ No newline at end of file