From 633c772c61744d09b39a886d891d93ed9f417bb8 Mon Sep 17 00:00:00 2001 From: Artem Horbunov Date: Thu, 2 Apr 2020 14:54:16 +0000 Subject: [PATCH] =?UTF-8?q?Aktualizovat=20=E2=80=9Edu4/program.c=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du4/program.c | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/du4/program.c b/du4/program.c index ecc299d..c2352c0 100644 --- a/du4/program.c +++ b/du4/program.c @@ -1,35 +1,15 @@ #include -int main() -{ - - int a, b; - scanf("%d%d", &a, &b); - float c; - scanf("%f", &c); - if (c==a+b) - printf("OK \n"); - else - printf("ZLE\n"); - scanf("%d%d", &a, &b); - scanf("%f", &c); - if (c==a*b) - printf("OK \n"); - else - printf("ZLE\n"); - scanf("%d%d", &a, &b); - scanf("%f", &c); - if (c==a/b) - printf("OK"); - else - printf("ZLE \n"); - scanf("%d%d", &a, &b); - scanf("%f", &c); - if (c==a/b) - printf("OK \n"); - else - printf("ZLE \n"); - return 0; - - +int main(){ + char read[1000000]; + scanf("%[^\n]", read); + int num1, num2, answer; + char action; + sscanf(read, "%d %c %d %*c %d", &num1, &action, &num2, &answer); + if(action != '/' || action != '*' || action != '-' ||action != '+'){ + printf("CHYBA\n"); + return -1; + } + int check = (action == '/') ? num1 / num2 : (action == '*') ? num1 * num2 : (action == '+') ? num1 + num2 : num1 - num2; + printf("%s\n", (check == answer) ? "OK" : "ZLE"); }