158 lines
3.8 KiB
Plaintext
158 lines
3.8 KiB
Plaintext
#include <stdio.h>
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
char array[100];
|
|
char array1[100];
|
|
char number1[100];
|
|
char number2[100];
|
|
char answer[100];
|
|
int p=0;
|
|
float zero=0;
|
|
char znak1;
|
|
char znak2;
|
|
float firstN=0;
|
|
float secondN=0;
|
|
float answer1=0;
|
|
float myAnswer=0;
|
|
char c;
|
|
char r;
|
|
char q;
|
|
int count = 0;
|
|
int scan(char* array2){
|
|
char* r = fgets(array1,100,stdin);
|
|
if (r == NULL){
|
|
return -1;
|
|
}
|
|
else{
|
|
return 0;
|
|
}
|
|
}
|
|
int main(){
|
|
scan(array1);
|
|
int i=0;
|
|
while(i<100){
|
|
i=i+1;
|
|
if(array1[i]!='\n'){
|
|
count=count+1;
|
|
}
|
|
if(array1[i]=='\n'){
|
|
if(array1[i+1]=='\n')
|
|
{
|
|
array1[i]='#';
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
count=count+1;
|
|
}
|
|
}
|
|
i=0;
|
|
int j=0;
|
|
int t=0;
|
|
while(array1[t]!='#'){
|
|
array[p]=array1[t];
|
|
if(array1[t]=='='){
|
|
t=t+1;
|
|
p=p+1;
|
|
if(array1[t]==' '){
|
|
array[p]=array1[t];
|
|
t=t+1;
|
|
p=p+1;
|
|
}
|
|
while(array1[t]!=' ')
|
|
{
|
|
if(array1[t]=='#'){
|
|
break;
|
|
}
|
|
array[p]=array1[t];
|
|
t=t+1;
|
|
p=p+1;
|
|
}
|
|
while(array[i]!='\0'){
|
|
if(array[i]=='+'||array[i]=='-'||array[i]=='/'||array[i]=='*'){
|
|
break;
|
|
}
|
|
else if(array[i]=='1'||array[i]=='2'||array[i]=='3'||array[i]=='4'||array[i]=='5'||array[i]=='6'||array[i]=='7'||array[i]=='8'||array[i]=='9'||array[i]=='0'||array[i]=='.'){
|
|
number1[j]= array[i];
|
|
i=i+1;
|
|
j=j+1;
|
|
}
|
|
else if(array[i]==' ' || isalpha(array[i])){i++;}
|
|
else{
|
|
printf("CHYBA\n");
|
|
return 0;
|
|
}
|
|
}
|
|
znak1=array[i];
|
|
i=i+1;
|
|
j=0;
|
|
while(array[i]!='='){
|
|
if(array[i]=='1'||array[i]=='2'||array[i]=='3'||array[i]=='4'||array[i]=='5'||array[i]=='6'||array[i]=='7'||array[i]=='8'||array[i]=='9'||array[i]=='0'||array[i]=='.'){
|
|
number2[j]=array[i];
|
|
j=j+1;
|
|
i=i+1;
|
|
}
|
|
else if(array[i]==' '){
|
|
i=i+1;
|
|
}
|
|
else{
|
|
i=i+1;
|
|
p=p+1;
|
|
}
|
|
}
|
|
znak2=array[i];
|
|
i++;
|
|
j=0;
|
|
j=0;
|
|
while(array[i]=='1'||array[i]=='2'||array[i]=='3'||array[i]=='4'||array[i]=='5'||array[i]=='6'||array[i]=='7'||array[i]=='8'||array[i]=='9'||array[i]=='0'||array[i]==' '||array[i]=='.'){
|
|
if(array[i]=='1'||array[i]=='2'||array[i]=='3'||array[i]=='4'||array[i]=='5'||array[i]=='6'||array[i]=='7'||array[i]=='8'||array[i]=='9'||array[i]=='0'||array[i]=='.'){
|
|
answer[j]=array[i];
|
|
i=i+1;
|
|
j=j+1;
|
|
}
|
|
else if(array[i]==' '){
|
|
i=i+1;
|
|
}else{
|
|
i=i+1;
|
|
p=p+1;
|
|
}
|
|
}
|
|
j=0;
|
|
float firstN = atof(number1);
|
|
float secondN = atof(number2);
|
|
float answer1 = atof(answer);
|
|
if(znak1=='-'){
|
|
myAnswer=firstN-secondN;
|
|
}
|
|
else if(znak1=='+'){
|
|
myAnswer=firstN+secondN;
|
|
}
|
|
else if(znak1=='/'){
|
|
myAnswer=firstN/secondN;
|
|
}
|
|
else if(znak1=='*'){
|
|
myAnswer=firstN*secondN;
|
|
}
|
|
zero = myAnswer-answer1;
|
|
if(zero>=-0.00001&&zero<=0.00001){
|
|
printf("OK\n");
|
|
}
|
|
else{
|
|
printf("ZLE\n");
|
|
}
|
|
i=0;
|
|
p=-1;
|
|
memset(array,0,100);
|
|
}
|
|
p=p+1;
|
|
t=t+1;
|
|
scanf("\n%c",&q);
|
|
if(c=='\n'){
|
|
return 0;
|
|
}
|
|
}
|
|
return 0;
|
|
} |