86 lines
2.0 KiB
C
86 lines
2.0 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include <stdbool.h>
|
|
#define SIZE 100
|
|
|
|
bool checkZnaka(char znaky[],char znak1){
|
|
for(int i = 0;i < 4;i++){
|
|
if(znaky[i] == znak1){
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
struct vzorec{
|
|
double x;
|
|
double y;
|
|
double result;
|
|
char znak1;
|
|
char znak2;
|
|
};
|
|
|
|
int main(){
|
|
char a,b,c,d,f;
|
|
int results[SIZE];
|
|
char line[SIZE];
|
|
char znaky[] = "+-*/";
|
|
memset(line,0,SIZE);
|
|
struct vzorec funkcia[SIZE];
|
|
memset(funkcia,0,SIZE);
|
|
char* pEnd;
|
|
int counter = 0;
|
|
double realRes = 0;
|
|
while (fgets(line,SIZE,stdin) && line[0] != '\n'){
|
|
if(line == NULL){
|
|
break;
|
|
}
|
|
int n = sscanf(line, "%lf %c %lf %c %lf", &funkcia->x, &funkcia->znak1, &funkcia->y, &funkcia->znak2, &funkcia->result);
|
|
int n1 = sscanf(line, "%c %c %c %c %c", &a, &b, &c, &d, &f);
|
|
if(a != funkcia->x || c != funkcia->y || f > funkcia->result){
|
|
results[counter] = 1;
|
|
counter++;
|
|
continue;
|
|
|
|
}
|
|
if(checkZnaka(znaky, funkcia->znak1) == true || funkcia->znak2 != '='){
|
|
results[counter] = 1;
|
|
counter++;
|
|
continue;
|
|
}
|
|
if(funkcia->znak1 == '+')
|
|
realRes = round((funkcia->x + funkcia->y) * 100) / 100.0;
|
|
if(funkcia->znak1 == '-')
|
|
realRes = round((funkcia->x - funkcia->y) * 100) / 100.0;
|
|
if(funkcia->znak1 == '*')
|
|
realRes = round((funkcia->x * funkcia->y) * 100) / 100.0;
|
|
if(funkcia->znak1 == '/')
|
|
realRes = round((funkcia->x / funkcia->y) * 100) / 100.0;
|
|
if(funkcia->result != realRes){
|
|
results[counter] = 2;
|
|
counter++;
|
|
continue;
|
|
}
|
|
else{
|
|
results[counter] = 3;
|
|
counter++;
|
|
continue;
|
|
}
|
|
}
|
|
for(int i = 0; i <= counter;i++){
|
|
if(results[i] == 1){
|
|
printf("CHYBA\n");
|
|
}
|
|
if(results[i] == 2){
|
|
printf("ZLE\n");
|
|
}
|
|
if(results[i] == 3){
|
|
printf("OK\n");
|
|
}
|
|
}
|
|
return 0;
|
|
} |