This commit is contained in:
Yaroslav Orlianskyi 2022-03-30 23:36:37 +02:00
parent b3516cc6c7
commit f0d910c22f
4 changed files with 62 additions and 99 deletions

Binary file not shown.

View File

@ -1,54 +1,57 @@
#include <stdio.h>
#include <stdbool.h>
int main ()
{
int c, vysledok, i = 0;
int b[99];
bool first = true;
bool second = false;
int main (){
char riadok[999];
char *endptr = NULL;
char need;
int i, a, vysledok = 0;
float c[99];
while(1){
c = getchar();
if(c == ' ' || c == '+' || c == '\n' || c == '-' || c == '/' || c == '*' || c == '='){
if(c == '\n'){
char* r = fgets(riadok,999,stdin);
riadok[i++] = *r;
if(*r == '\n')
break;
}else if(c == ' '){
continue;
}else if(c == '='){
continue;
}else if(c == '+'){
first = true;
second = true;
continue;
}else if(c == '-'){
first = false;
second = false;
continue;
}else if(c == '/'){
first = true;
second = false;
continue;
}else if(c == '*'){
first = false;
second = true;
continue;
}
int j = 0;
do{
if(riadok[j] == ' '){
j++;
continue;
}else if(riadok[j] == '+'){
need = riadok[j];
j++;
continue;
}else if(riadok[i] == '/'){
need = riadok[j];
j++;
continue;
}else if(riadok[i] == '-'){
need = riadok[j];
j++;
continue;
}else if(riadok[j] == '*'){
need = riadok[j];
j++;
continue;
}else if(riadok[j] == '='){
if(need == '+')
vysledok = c[0] + c[1];
else if(need == '-')
vysledok = c[0] - c[1];
else if(need == '/')
vysledok = c[0] / c[1];
else if(need == '*')
vysledok = c[0] * c[1];
j++;
continue;
}else{
c = 0;
int r = scanf("%d",&c);
b[i++] = c;
float v = strtod(riadok,&endptr);
c[a] = v;
a = a + 1;
}
}
if(first == true && second == true)
vysledok = b[0] + b[1];
else if(first == false && second == false)
vysledok = b[0] - b[1];
else if(first == true && second == false)
vysledok = b[0] / b[1];
else if(first == false && second == true)
vysledok = b[0] * b[1];
if(vysledok == b[2])
}while(j < i);
if(vysledok == c[2])
printf("OK\n");
else
printf("ZLE\n");
return 0;
}

BIN
du4/test

Binary file not shown.

View File

@ -1,57 +1,17 @@
#include <stdio.h>
#include <stdbool.h>
int main ()
{
int c, vysledok, i = 0;
int b[99];
bool first = true;
bool second = false;
int main(){
char riadok[555];
int i, j = 0;
while(1){
c = getchar();
if(c <= 255 && c >= 0){
if(c == '\n'){
riadok[i] = getchar();
if(riadok[i] == '\n')
break;
}else if(c == ' '){
continue;
}else if(c == '='){
continue;
}else if(c == '+'){
first = true;
second = true;
continue;
}else if(c == '-'){
first = false;
second = false;
continue;
}else if(c == '/'){
first = true;
second = false;
continue;
}else if(c == '*'){
first = false;
second = true;
continue;
}
}else{
if(i == 2)
break;
c = 0;
int r = scanf("%d",&c);
b[i++] = c;
}
}
if(first == true && second == true)
vysledok = b[0] + b[1];
else if(first == false && second == false)
vysledok = b[0] - b[1];
else if(first == true && second == false)
vysledok = b[0] / b[1];
else if(first == false && second == true)
vysledok = b[0] * b[1];
if(vysledok == b[2])
printf("OK\n");
else
printf("ZLE\n");
return 0;
i++;
}
do{
printf("%c\n", riadok[j]);
j++;
}while(j < i - 2);
}