Archived
1
0
Fork 0
This commit is contained in:
nihonium 2022-03-03 18:59:11 +03:00
parent d6189d57bc
commit 4c7c133abf
4 changed files with 340 additions and 0 deletions

30
data/bit_3.c Normal file
View file

@ -0,0 +1,30 @@
#include <stdio.h>
int main() {
FILE *input = fopen("bit_3.dat","r");
int nya;
char t;
fscanf(input, "%x\n", &nya);
fclose(input);
t = (nya >> 4) & 1;
t += ((nya >> 5) & 1) * 2;
FILE *output = fopen("bit_3.ans","w");
switch (t) {
case 3:
fprintf(output, "%s", "bk");
break;
case 2:
fprintf(output, "%s", "bw");
break;
case 1:
fprintf(output, "%s", "rd");
break;
case 0:
fprintf(output, "%s", "bn");
break;
}
fclose(output);
}

37
data/bit_4.c Normal file
View file

@ -0,0 +1,37 @@
#include <stdio.h>
const char* gender[] = {"fe", "ma"};
const char* intel[] = {"du", "cl"};
const char* hat[] = {"nh", "ha"};
const char* legs[] = {"sk", "tr"};
const char* hair[] = {"bn", "rd", "bw", "bk"};
const char* eyes[] = {"bu", "ge", "gy", "da"};
void print_feature(int x, const char* features[], int bit, int len);
int main() {
int nya;
scanf("%x", &nya);
print_feature(nya, gender, 0, 1);
print_feature(nya, intel, 1, 1);
print_feature(nya, hat, 2, 1);
print_feature(nya, legs, 3, 1);
print_feature(nya, hair, 4, 2);
print_feature(nya, eyes, 6, 2);
return 0;
}
void print_feature(int x, const char* features[], int bit, int len) {
int t;
if (len == 1) {
t = (x >> bit) & 1;
}
else {
t = (x >> bit) & 1;
t += ((x >> (bit + 1)) & 1) * 2;
}
printf("%s ", features[t]);
}

72
data/bit_5.c Normal file
View file

@ -0,0 +1,72 @@
#include <stdio.h>
#include <string.h>
const char* gender[] = {"fe", "ma"};
const char* intel[] = {"du", "cl"};
const char* hat[] = {"nh", "ha"};
const char* legs[] = {"sk", "tr"};
const char* hair[] = {"bn", "rd", "bw", "bk"};
const char* eyes[] = {"bu", "ge", "gy", "da"};
void add_feature(int *res, int val, int len, int pos);
int check_in(char *src, const char* feature[], int l);
int main() {
char x[1000] = "";
char buf[3] = "";
int res = 0;
int len, i, pos;
scanf("%[^\n]", x);
len = (int)strlen(x);
for (i = 0; i < len; i += 3) {
buf[0] = x[i];
buf[1] = x[i+1];
buf[2] = '\0';
if ((pos = check_in(buf, gender, 2)) != -1) {
add_feature(&res, pos, 1, 0);
}
if ((pos = check_in(buf, intel, 2)) != -1) {
add_feature(&res, pos, 1, 1);
}
if ((pos = check_in(buf, hat, 2)) != -1) {
add_feature(&res, pos, 1, 2);
}
if ((pos = check_in(buf, legs, 2)) != -1) {
add_feature(&res, pos, 1, 3);
}
if ((pos = check_in(buf, hair, 4)) != -1) {
add_feature(&res, pos, 2, 4);
}
if ((pos = check_in(buf, eyes, 4)) != -1) {
add_feature(&res, pos, 2, 6);
}
}
printf("%x", res);
}
void add_feature(int *res, int val, int len, int pos) {
int mask;
if (len == 1) {
mask = 1 << pos;
*res = ((*res & ~mask) | (val << pos));
}
else {
mask = 1 << pos;
*res = ((*res & ~mask) | ((val % 2)<< pos));
mask = 1 << (pos + 1);
*res = ((*res & ~mask) | ((int)(val / 2)<< (pos + 1)));
}
}
int check_in(char *src, const char* feature[], int l) {
int i;
for (i = 0; i < l; ++i) {
if (!strcmp(feature[i], src)) {
return i;
}
}
return -1;
}