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;
} }
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{ }else{
c = 0; float v = strtod(riadok,&endptr);
int r = scanf("%d",&c); c[a] = v;
b[i++] = c; a = a + 1;
} }
} }while(j < i);
if(first == true && second == true) if(vysledok == c[2])
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"); 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 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 else
printf("ZLE\n"); i++;
return 0; }
do{
printf("%c\n", riadok[j]);
j++;
}while(j < i - 2);
} }