nihonium
/
mipt_clang
Archived
1
0
Fork 0
remotes/private/master
nihonium 3 years ago
parent d6189d57bc
commit 4c7c133abf

@ -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);
}

@ -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]);
}

@ -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;
}

@ -0,0 +1,201 @@
/*
Not fully working!
Shitty solution.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main () {
char a[1001] = "", b[1001] = "", c[1002]= "";
//char* a = (char*)calloc(1001, sizeof(char));
//char* b = (char*)calloc(1001, sizeof(char));
//char* c = (char*)calloc(1002, sizeof(char));
int i;
char x = '0';
scanf("%s\n%s", a, b);
char cf = '0'; /* '0', '1', '$' */
int len_a = strlen(a);
int len_b = strlen(b);
if (len_a < len_b) {
strcpy(c, a);
strcpy(a, b);
strcpy(b, c);
}
for (i = 1; i <= len_b; ++i) {
//printf("len:%d\n", len_a-i);
//printf("%d: (cf=%c):", i, cf);
// 0 + 0
if ((a[len_a-i] == '0') && (b[len_b-i] == '0')) {
x = cf;
cf = '0';
}
// $ + $
else if ((a[len_a-i] == '$') && (b[len_b-i] == '$')) {
if (cf == '0') {
x = '1';
cf = '$';
}
else if (cf == '1') {
x = '$';
cf = '0';
}
else if (cf == '$') {
x = '0';
cf = '$';
}
}
//1 + 1
else if ((a[len_a-i] == '1') && (b[len_b-i] == '1')) {
if (cf == '0') {
x = '$';
cf = '1';
}
else if (cf == '1') {
x = '0';
cf = '1';
}
else if (cf == '$') {
x = '1';
cf = '0';
}
}
// smth + 0 = same as non-zero
else if (a[len_a-i] == '0') {
if (cf == '0') {
x = b[len_b-i];
cf = '0';
}
else if (cf == '1') {
if (b[len_b-i] == '0') {
x = cf;
cf = '0';
}
else if (b[len_b-i] == '1') {
x = '$';
cf = '1';
}
else if (b[len_b-i] == '$') {
x = '0';
cf = '0';
}
}
else if (cf == '$') {
if (b[len_b-i] == '0') {
x = cf;
cf = '0';
}
else if (b[len_b-i] == '1') {
x = '0';
cf = '0';
}
else if (b[len_b-i] == '$') {
x = '1';
cf = '$';
}
}
}
else if (b[len_b-i] == '0') {
if (cf == '0') {
x = a[len_a-i];
cf = '0';
}
else if (cf == '1') {
if (a[len_a-i] == '0') {
x = cf;
cf = '0';
}
else if (a[len_a-i] == '1') {
x = '$';
cf = '1';
}
else if (a[len_a-i] == '$') {
x = '0';
cf = '0';
}
}
else if (cf == '$') {
if (a[len_a-i] == '0') {
x = cf;
cf = '0';
}
else if (a[len_a-i] == '1') {
x = '0';
cf = '0';
}
else if (a[len_a-i] == '$') {
x = '1';
cf = '$';
}
}
}
// 1 + $
else if (a[len_a-i] == '$' || b[len_b-i] == '$' ) {
x = cf;
cf = '0';
}
//printf("%c + %c = %c (cf = %c)\n", a[len_a-i], b[len_b-i], x, cf);
c[len_a-i] = x;
}
for (; i <= len_a; ++i) {
// 0 + 0
if ((a[len_a-i] == '0') && (cf == '0')) {
x = '0';
}
// $ + $
else if ((a[len_a-i] == '$') && (cf == '$')) {
x = '1';
cf = '$';
}
//1 + 1
else if ((a[len_a-i] == '1') && (cf == '1')) {
x = '$';
cf = '1';
}
// smth + 0 = same as non-zero
else if (a[len_a-i] == '0') {
x = cf;
cf = '0';
}
else if (cf == '0') {
x = a[len_a-i];
}
// 1 + $
else if (a[len_a-i] == '$' || cf == '$' ) {
x = '0';
cf = '0';
}
c[len_a-i] = x;
}
c[i] = '\0';
for (i = 0; c[i] == '0'; ++i);
//printf("%c\n", cf);
if (i == len_a) {
if (cf == '1')
printf("1");
else if (cf == '$')
printf("$");
else
printf("0");
}
else {
if (cf != '0') {
if (cf == '1')
printf("1%s", c+i);
if (cf == '$')
printf("$%s", c+i);
}
else
printf("%s", c+i);
}
//free(a);
//free(b); free(c);
return 0;
}