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

BIN
du4/test

Binary file not shown.

View File

@ -1,57 +1,17 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
int main () int main(){
{ char riadok[555];
int c, vysledok, i = 0; int i, j = 0;
int b[99];
bool first = true;
bool second = false;
while(1){ while(1){
c = getchar(); riadok[i] = getchar();
if(c <= 255 && c >= 0){ if(riadok[i] == '\n')
if(c == '\n'){ break;
break; else
}else if(c == ' '){ i++;
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) do{
vysledok = b[0] + b[1]; printf("%c\n", riadok[j]);
else if(first == false && second == false) j++;
vysledok = b[0] - b[1]; }while(j < i - 2);
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;
} }