63 lines
1.1 KiB
C
63 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include<string.h>
|
|
#include<stdlib.h>
|
|
char* compactString(char *src,int leng) {
|
|
char *new_str = (char*)calloc(leng+1,sizeof(char));
|
|
int k=0;
|
|
for(int i=0;i<leng;i++){
|
|
if(src[i]!=' '){
|
|
new_str[k] = src[i];
|
|
k++;
|
|
}
|
|
}
|
|
return new_str;
|
|
}
|
|
|
|
|
|
|
|
double operation(double first,double second,char c){
|
|
if(c=='*'){
|
|
return first*second;
|
|
}
|
|
else if(c =='-'){
|
|
return first-second;
|
|
}
|
|
else if(c=='/'){
|
|
return first/second;
|
|
}
|
|
return first+second;
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
{
|
|
char str[100];
|
|
memset(str,0,100);
|
|
fgets(str,100,stdin);
|
|
char *new_str = compactString(str,strlen(str));
|
|
printf("%s\n",new_str);
|
|
double first =-5,second =-5,res=-5;
|
|
char c='E';
|
|
sscanf(new_str,"%lf%c%lf%*[=]%lf",&first,&c,&second,&res);
|
|
// printf("%lf %lf %lf",first,second,res);
|
|
|
|
|
|
|
|
|
|
if(c=='E'||first==-5||second==-5||res==-5){
|
|
printf("CHYBA\n");
|
|
return 0;
|
|
}
|
|
double my_res = operation(first,second,c);
|
|
if(my_res==res){
|
|
printf("OK\n");
|
|
}
|
|
else{
|
|
printf("ZLE\n");
|
|
}
|
|
|
|
|
|
return 0;
|
|
}
|