Mai intai trebuie sa te autentifici.
Cod sursa(job #2956540)
Utilizator | Data | 19 decembrie 2022 18:48:22 | |
---|---|---|---|
Problema | Bool | Scor | 100 |
Compilator | c-64 | Status | done |
Runda | Arhiva de probleme | Marime | 2.16 kb |
#include <stdio.h>
#include <stdint.h>
char st[1001];
char *__restrict s = st;
int8_t a[40] = {0};
int8_t or();
int8_t and();
int8_t item() {
int8_t sgn = 0;
int8_t t = 0;
while (*s == '-') {
++s;
sgn ^= 1;
}
if (*s == '(') {
++s;
t = or();
++s;
return t ^ sgn;
} else if ('A' <= *s && *s <= 'Z') {
t = a[*s - 'A'];
} else if (*s == '1') {
t = 1;
} else if (*s == '0') {
t = 0;
}
++s;
return t ^ sgn;
}
int8_t and() {
int8_t t = item();
while (*s == '&') {
++s;
t *= item();
}
return t;
}
int8_t or() {
int8_t t = and();
while (*s == '|') {
++s;
t |= and();
}
return t;
}
void read_str(FILE *__restrict stream, char *__restrict str) {
while ((*str = fgetc(stream))) {
if (*str == '\r' || *str == '\n' || *str == '\0') {
*str = '\0';
return;
}
++str;
}
}
#define C(v,e,d) {case v:{if (str[1]==e){d;}else{*r=v;++str;}}break;}
void parse_str(char *__restrict str, char *__restrict r) {
while (*str != '\0') {
switch (*str) {
case ' ':
--r;
++str;
break;
C('A', 'N',
str += 3;
*r = '&';)
C('O', 'R',
str += 2;
*r = '|')
C('T', 'R',
str += 4;
*r = '1')
C('F', 'A',
str += 5;
*r = '0')
C('N', 'O',
str += 3;
*r = '-')
default:
*r = *str;
++str;
break;
}
++r;
}
*r = '\0';
}
void read_uint32_t(FILE *__restrict stream, uint32_t *__restrict nr) {
uint8_t ch;
*nr = 0;
while ((ch = fgetc(stream)) && ('0' <= ch && ch <= '9')) {
*nr *= 10;
*nr += ch - '0';
}
if (ch == '\r') {
fgetc(stream);
}
}
int main(void) {
char cs[1001];
uint32_t n;
{
FILE *__restrict in = fopen("bool.in", "r");
FILE *__restrict out = fopen("bool.out", "w");
read_str(in, cs);
parse_str(cs, st);
read_uint32_t(in, &n);
//fprintf(stdout, "%s\n", st);
{
int32_t i;
for(i = 0; i < n; ++i) {
a[fgetc(in) - 'A'] ^= 1;
s = st;
fprintf(out, "%i", or());
}
}
fclose(out);
fclose(in);
}
return 0;
}