1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 | #include <time.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const char*Questions[]={"\101\162\145\40\171\157\165\40\164\162\141\156\163\147\145\156\144\145\162\77"
,"\101\162\145\40\171\157\165\40\147\141\171\57\154\145\163\142\151\141\156\57\142\151\57\145\164\143\56\77"
,"\101\162\145\40\171\157\165\40\141\156\40\141\144\165\154\164\77","\104\157\40\171\157\165\40\153\156\157\167\40\103\53\53\40\167\145\154\154\77"
,"\101\162\145\40\171\157\165\40\143\165\162\162\145\156\164\154\171\40\151\156\40\141\40\162\145\154\141\164\151\157\156\163\150\151\160\77"
,"\101\162\145\40\171\157\165\40\141\40\160\141\162\164\40\157\146\40\164\150\145\40\163\164\141\146\146\77"
,"\101\162\145\40\171\157\165\40\143\165\162\162\145\156\164\154\171\40\151\156\40\163\143\150\157\157\154\77"
,"\104\157\40\171\157\165\40\150\141\166\145\40\171\157\165\162\40\157\167\156\40\104\151\163\143\157\162\144\40\163\145\162\166\145\162\77\40\50\144\157\145\163\156\47\164\40\151\156\143\154\165\144\145\40\"\164\145\163\164\40\163\145\162\166\145\162\163\"\51"
,"\104\157\40\171\157\165\40\150\141\166\145\40\141\40\107\151\164\110\165\142\40\141\143\143\157\165\156\164\77"
,"\104\157\40\171\157\165\40\154\151\166\145\40\151\156\40\164\150\145\40\125\56\123\56\101\56\77"
,"\104\157\40\171\157\165\40\162\157\165\164\151\156\145\154\171\40\145\170\145\162\143\151\163\145\77"
,"\110\141\166\145\40\171\157\165\40\145\166\145\162\40\150\141\144\40\141\40\160\145\164\77"
,"\104\157\40\171\157\165\40\162\145\147\165\154\141\162\154\171\40\165\163\145\40\122\165\163\164\77"
,"\104\157\40\171\157\165\40\157\146\164\145\156\40\164\162\171\40\164\157\40\160\162\157\147\162\141\155\40\151\156\40\145\163\157\164\145\162\151\143\40\160\162\157\147\162\141\155\155\151\156\147\40\154\141\156\147\165\141\147\145\163\77"
,"\101\162\145\40\171\157\165\40\141\40\160\141\162\164\40\157\146\40\164\150\145\40\107\105\117\122\107\105\40\167\145\142\162\151\156\147\77"
,"\104\157\40\171\157\165\40\150\141\166\145\40\155\157\162\145\40\164\150\141\156\40\61\60\40\107\151\164\110\165\142\40\162\145\160\157\163\151\164\157\162\151\145\163\77"
,"\124\141\142\163\40\50\131\51\40\157\162\40\163\160\141\143\145\163\40\50\116\51\77"
,"\111\163\40\160\162\157\147\162\141\155\155\151\156\147\40\171\157\165\162\40\160\162\151\155\141\162\171\40\150\157\142\142\171\77"
,"\104\157\40\160\145\157\160\154\145\40\143\141\154\154\40\171\157\165\40\142\171\40\171\157\165\162\40\156\151\143\153\156\141\155\145\57\162\145\141\154\40\156\141\155\145\40\155\157\162\145\40\157\146\164\145\156\40\164\150\141\156\40\171\157\165\162\40\165\163\145\162\156\141\155\145\57\157\156\154\151\156\145\40\156\141\155\145\77"
,"\140\151\146\50\56\56\56\51\140\40\50\131\51\40\157\162\40\140\151\146\40\50\56\56\56\51\140\40\50\116\51\77"
,"\104\157\40\171\157\165\40\141\143\164\151\166\145\154\171\40\160\141\162\164\151\143\151\160\141\164\145\40\151\156\40\164\150\145\40\105\163\157\154\141\156\147\163\40\143\157\155\155\165\156\151\164\171\77\40\50\151\145\56\40\144\145\166\145\154\157\160\40\141\156\144\40\165\164\151\154\151\172\145\40\145\163\157\154\141\156\147\163\51"
,"\104\157\40\171\157\165\40\145\156\152\157\171\40\154\151\156\147\165\151\163\164\151\143\163\77\40\50\145\147\56\40\143\157\156\154\141\156\147\163\51"
,"\104\157\40\171\157\165\40\165\163\145\40\127\151\156\144\157\167\163\40\160\162\151\155\141\162\151\154\171\77"
,"\127\157\165\154\144\40\171\157\165\40\143\157\156\163\151\144\145\162\40\171\157\165\162\163\145\154\146\40\141\40\"\143\157\155\160\165\164\145\162\40\167\150\151\172\"\77"
,"\101\162\145\40\171\157\165\40\143\157\156\164\145\156\164\40\167\151\164\150\40\171\157\165\162\40\143\165\162\162\145\156\164\40\154\151\166\151\156\147\40\163\151\164\165\141\164\151\157\156\77"
,"\104\157\40\171\157\165\40\160\162\151\155\141\162\151\154\171\40\165\163\145\40\120\171\164\150\157\156\77\40\50\151\145\56\40\165\163\145\40\151\164\40\155\157\162\145\40\157\146\164\145\156\40\164\150\141\156\40\157\164\150\145\162\40\154\141\156\147\165\141\147\145\163\51"
,"\101\162\145\40\171\157\165\40\141\40\"\154\157\156\147\55\163\164\141\156\144\151\156\147\"\40\155\145\155\142\145\162\40\157\146\40\105\163\157\154\141\156\147\163\77"
,"\104\157\40\171\157\165\40\150\141\166\145\40\141\40\50\155\145\141\156\151\156\147\146\165\154\51\40\167\145\142\163\151\164\145\77"
,"\101\162\145\40\171\157\165\40\143\165\162\162\145\156\164\154\171\40\151\156\40\150\151\147\150\40\163\143\150\157\157\154\77"
,"\110\141\166\145\40\171\157\165\40\145\166\145\162\40\160\141\162\164\151\143\151\160\141\164\145\144\40\151\156\40\143\157\144\145\40\147\165\145\163\163\151\156\147\77"
,"\110\141\166\145\40\171\157\165\40\145\166\145\162\40\150\141\144\40\141\40\114\171\162\151\143\114\171\40\157\162\40\147\157\154\154\141\162\153\40\156\141\155\145\40\144\145\162\151\166\141\164\151\166\145\77"
,"\101\162\145\40\171\157\165\40\146\162\157\155\40\105\165\162\157\160\145\77"
,"\110\141\166\145\40\171\157\165\40\145\166\145\162\40\144\145\166\145\154\157\160\145\144\40\146\157\162\40\141\156\40\145\155\142\145\144\144\145\144\40\163\171\163\164\145\155\77"
,"\101\162\145\40\171\157\165\40\155\165\154\164\151\154\151\156\147\165\141\154\77"
,"\111\163\40\105\156\147\154\151\163\150\40\171\157\165\162\40\160\162\151\155\141\162\171\40\154\141\156\147\165\141\147\145\77"
,""};typedef struct{char name[(7*(2*1+0)+6)+(2*(1*1+0)+0)];unsigned char q[((
sizeof(Questions)/sizeof(Questions[0]))-(1*(1*1+0)+0))+(1*(1*1+0)+0)];}tdat;
typedef struct{tdat info;float chance;}character;static character*Characters;
static unsigned int CharactersLen=0;static tdat*TrainingDat;static unsigned
int TrainingDatLen=0;static unsigned char CurAns[((sizeof(Questions)/sizeof(
Questions[0]))-(1+0))+(0+1)];static unsigned int Target=0;static float chance(
character*C){unsigned int e=0;for(unsigned int i=0;i!=((sizeof(Questions)/
sizeof(Questions[0]))-(1*1+0));i++){if((CurAns[i]==0)||(C->info.q[i]==0))
continue;if(CurAns[i]==C->info.q[i])e++;else e=((int)e-(int)(((sizeof(
Questions)/sizeof(Questions[0]))-(1*(1*1+0)+0))/(1+1))<0)?0:e-(((sizeof(
Questions)/sizeof(Questions[0]))-(1*1+0))/(1+1));}return(C->chance=(float)e/(
float)((sizeof(Questions)/sizeof(Questions[0]))-(1*(1*1+0)+0)));}static
unsigned char parseans(char a){switch(a){case'Y':case'y':case'T':case't':
return (1+1);case'N':case'n':case'F':case'f':return (1*1+0);default:return 0;}
}static unsigned int highestchance(void){float curch=0;unsigned int h=0;for(
unsigned int c=0;c!=CharactersLen;c++){if(chance(&Characters[c])>curch){curch=
Characters[c].chance;h=c;}}return h;}static void train(unsigned int qu,
unsigned char an){Target=highestchance();CurAns[qu]=an;}static unsigned char
loadchars(void){{char answers[((sizeof(Questions)/sizeof(Questions[0]))-(1+0))
+(1*(2*1+0)+0)];FILE*f=fopen("\56\164\144","\162");if(f==NULL)return
(1*(1*1+0)+0);unsigned int ent;for(ent=0;;ent++){{char fmt[(20*1+0)];snprintf(
fmt,(sizeof(fmt)/sizeof(fmt[0])),
"\45\45\45\165\133\136\54\135\54\45\45\45\165\133\136\n\135\n",(unsigned int)(
(10+10)+(0+1)),(unsigned int)((sizeof(Questions)/sizeof(Questions[0]))-(0+1))+
(0+1));if(fscanf(f,fmt,TrainingDat[ent].name,answers)==EOF)goto done;}if(ent>=
TrainingDatLen)TrainingDat=(tdat*)realloc(TrainingDat,((TrainingDatLen*=1.5)+
(1*(1*1+0)+0))*sizeof(tdat));for(unsigned int i=0;i!=((sizeof(Questions)/
sizeof(Questions[0]))-(1*1+0));i++)TrainingDat[ent].q[i]=parseans(answers[i]);
}done:TrainingDatLen=CharactersLen=ent;fclose(f);}TrainingDat=(tdat*)realloc(
TrainingDat,(TrainingDatLen+(0+1))*sizeof(tdat));Characters=(character*)malloc
((CharactersLen+(2*(1*1+0)+0))*sizeof(character));for(unsigned int ent=0;ent!=
TrainingDatLen;ent++){for(unsigned char i=0;i!=(10+10);i++)Characters[ent].
info.name[i]=TrainingDat[ent].name[i];for(unsigned int i=0;i!=((sizeof(
Questions)/sizeof(Questions[0]))-(1+0));i++)Characters[ent].info.q[i]=
TrainingDat[ent].q[i];Characters[ent].chance=0;}return 0;}static unsigned char
savechars(void){FILE*f=fopen("\56\164\144","\167");if(f==NULL)return
(1*(1*1+0)+0);for(unsigned int ent=0;ent!=CharactersLen;ent++){char answers[((
sizeof(Questions)/sizeof(Questions[0]))-(0+1))+(1*2+0)];for(unsigned int qu=0;
qu!=((sizeof(Questions)/sizeof(Questions[0]))-(1*1+0))+(1*1+0);qu++){switch(
Characters[ent].info.q[qu]){case (1+1):answers[qu]='T';break;case (1+0):
answers[qu]='F';break;case 0:answers[qu]='?';break;}}answers[((sizeof(
Questions)/sizeof(Questions[0]))-(1*1+0))+(0+1)]='\0';fprintf(f,
"\45\163\54\45\163\n",Characters[ent].info.name,answers);}fclose(f);return 0;}
static unsigned int getquestion(void){unsigned int q;for(;;){while(CurAns[(q=
rand()%(((sizeof(Questions)/sizeof(Questions[0]))-(1*1+0))))]!=0);if((rand()%
(1+1))==0){if(Characters[Target].info.q[q]==0)return q;}else return q;}}static
void init(void){free(TrainingDat);free(Characters);TrainingDat=(tdat*)malloc(
((TrainingDatLen=100)+(1*(1*1+0)+0))*sizeof(tdat));for(unsigned int i=0;i!=((
sizeof(Questions)/sizeof(Questions[0]))-(0+1));i++)CurAns[i]=0;srand(time(0));
}static void deinit(void){free(TrainingDat);free(Characters);TrainingDatLen=0;
CharactersLen=0;}static void init_td(void){const char initialcsv[]="\154\171\162\151\143\154\171\54\77\77\106\106\77\77\106\106\124\77\106\77\77\124\77\124\106\124\77\106\77\124\106\106\124\124\77\77\106\124\77\77\106\106\77\77\n\153\151\164\54\124\124\77\124\77\77\77\77\77\77\106\77\77\106\106\124\124\124\124\106\124\106\106\77\124\106\77\77\124\77\106\77\106\77\124\77\n\151\163\157\54\106\124\106\77\106\106\124\77\124\124\77\124\106\77\106\106\77\124\106\77\124\77\77\106\77\77\106\106\77\106\77\106\77\77\77\77\n\165\155\156\151\153\157\163\54\106\77\77\77\77\77\124\77\77\106\77\124\106\77\106\77\77\77\124\77\106\106\106\124\77\106\124\106\106\124\124\124\124\77\106\77\n\151\146\143\157\154\164\162\141\156\163\147\54\77\77\124\106\106\77\77\106\124\106\106\124\77\77\106\124\106\77\77\106\77\77\106\77\77\124\77\124\106\124\77\106\77\124\124\77\n\160\171\162\157\164\145\154\145\153\151\156\145\164\151\143\54\106\77\77\77\124\106\106\106\124\124\106\77\77\106\106\124\77\124\77\77\106\77\77\77\124\77\124\106\106\124\124\77\124\77\77\77"
;FILE*f=fopen("\56\164\144","\167");if(f==NULL)return;fprintf(f,"\45\163",
initialcsv);fclose(f);}static void trainchar(unsigned int c){for(unsigned int
q=0;q!=((sizeof(Questions)/sizeof(Questions[0]))-(1*(1*1+0)+0));q++){if(CurAns
[q]!=0){if(TrainingDat[c].q[q]==0)Characters[c].info.q[q]=CurAns[q];else if(
TrainingDat[c].q[q]!=CurAns[q])Characters[c].info.q[q]=0;}}}static void
insertchar(char*name){for(unsigned int c=0;c!=CharactersLen;c++){if(!strcmp(
Characters[c].info.name,name)){trainchar(c);return;}}for(unsigned char i=0;i!=
(15*1+5)+(1+0);i++)Characters[CharactersLen].info.name[i]=name[i];for(unsigned
int i=0;i!=((sizeof(Questions)/sizeof(Questions[0]))-(1*(1*1+0)+0));i++)
Characters[CharactersLen].info.q[i]=CurAns[i];CharactersLen++;}static unsigned
char getans(void){unsigned char ret;loop:if((ret=parseans(getchar()))==0)goto
loop;while(getchar()!='\n');return ret;}char*lcase(char*str){for(unsigned int
i=0;str[i];i++)if(str[i]>='A'&&str[i]<='Z')str[i]-='A'-'a';return str;}int
main(){begin:init();if(loadchars()){printf("\127\141\162\156\151\156\147\72\40\124\162\141\151\156\151\156\147\40\144\141\164\141\40\156\157\164\40\146\157\165\156\144\54\40\163\150\157\165\154\144\40\111\40\143\162\145\141\164\145\40\151\164\77\40\50\131\57\116\51\t"
);if(getans()==(1+1)){init_td();goto begin;}else{puts(
"\101\142\157\162\164\151\156\147");exit((0+1));}}for(unsigned char i=0;i!=
(13*1+7);i++){unsigned int qu=getquestion();printf(
"\45\165\t\45\163\40\50\131\57\116\51\t",i+(1*(1*1+0)+0),Questions[qu]);train(
qu,getans());}printf("\101\162\145\40\171\157\165\40\45\163\77\40",Characters[
Target].info.name);if(getans()==(1+1)){puts("\131\141\171\41");trainchar(
Target);}else{char name[(6*(3*1+0)+2)+(2*(1*1+0)+0)];char fmt[(12*1+8)];
snprintf(fmt,(sizeof(fmt)/sizeof(fmt[0])),"\45\45\45\165\133\136\n\135",(
unsigned int)((18*(1*1+0)+2)+(1*1+0)));do printf("\101\167\167\56\56\56\n\127\150\157\40\141\162\145\40\171\157\165\54\40\164\150\145\156\77\40"
);while(scanf(fmt,name)==EOF);insertchar(lcase(name));}savechars();deinit();}
|
post a comment