58 lines
1.4 KiB
C
58 lines
1.4 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{
|
|
int x;
|
|
int y;
|
|
int result;
|
|
char znak1;
|
|
char znak2;
|
|
};
|
|
|
|
int main(){
|
|
char line[SIZE];
|
|
char znaky[] = "+-*/";
|
|
memset(line,0,SIZE);
|
|
struct vzorec funkcia[SIZE];
|
|
memset(funkcia,0,SIZE);
|
|
char* pEnd;
|
|
while (fgets(line,SIZE,stdin) && line[0] != '\n'){
|
|
if(line == NULL){
|
|
break;
|
|
}
|
|
int n = sscanf(line, "%d %c %d %c %d", &funkcia->x, &funkcia->znak1, &funkcia->y, &funkcia->znak2, &funkcia->result);
|
|
if(checkZnaka(znaky, funkcia->znak1) == true || funkcia->znak2 != '=' || funkcia->x == 0 || funkcia->y == 0 || funkcia->result == 0){
|
|
printf("CHYBA");
|
|
return 0;
|
|
}
|
|
int r1 = funkcia->x + funkcia->y;
|
|
int r2 = funkcia->x - funkcia->y;
|
|
int r3 = funkcia->x * funkcia->y;
|
|
int r4 = funkcia->x / funkcia->y;
|
|
if(funkcia->result != r1 && funkcia->result != r2 && funkcia->result != r3 && funkcia->result != r4){
|
|
printf("ZLE");
|
|
return 0;
|
|
}
|
|
else{
|
|
printf("OK");
|
|
return 0;
|
|
}
|
|
printf("x: %d, znak1: %c, y: %d, znak2: %c, result: %d\n", funkcia->x, funkcia->znak1, funkcia->y, funkcia->znak2, funkcia->result);
|
|
}
|
|
return 0;
|
|
} |