-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog6.c
141 lines (124 loc) · 2.76 KB
/
prog6.c
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#define DATA_NUM 760
#define NUM_CODE 42
struct let_data
{
long int freq;
int id[2];
};
struct let_list
{
long int mam;
int letter[22223];
};
int print_char(int n);
int main(){
FILE *fp;
char c1[10];
int i,j,max_let,tmp,a1,a0,loop,flag,k[NUM_CODE]={0},atmp[NUM_CODE]={0};
long int mam=0;
struct let_list list[NUM_CODE];
struct let_data data[DATA_NUM];
char let[8];double prob;int rank;
for(i=0;i<NUM_CODE;i++){
list[i].mam=0;
}
srand((unsigned int)time(NULL));
if((fp=fopen("rslprog3n","r")) == NULL){
printf("Can not open txte file\n");
return -1;
}
fscanf(fp,"%s,%s,%s,%s,%s",c1,c1,c1,c1,c1);
i=0;
do{
fscanf(fp,"%d,%ld,%lf,%d %d,%s",&rank,&data[i].freq,&prob,&data[i].id[0],&data[i].id[1],let);
}while((data[i++].freq!=0)&&(i<DATA_NUM));
max_let=i;
for(i=0;i<max_let;i++){
for( ;k[data[i].id[0]]<atmp[data[i].id[0]]+data[i].freq/10; k[data[i].id[0]]++){
list[data[i].id[0]].letter[k[data[i].id[0]]]=data[i].id[1];
}
list[data[i].id[0]].mam+=data[i].freq/10;
atmp[data[i].id[0]]=k[data[i].id[0]];
}
for(i=0;i<NUM_CODE;i++){
mam+=list[i].mam;
}
loop=rand()%mam;
flag=0;j=0;tmp=0;
for(i=0;i<NUM_CODE;i++){
for( ;j<tmp+list[i].mam;j++){
if(j==loop){
print_char(i);
print_char(list[i].letter[j-tmp]);
a0=list[i].letter[j-tmp];
flag=1;
break;
}
}
if(flag) break;
tmp=j;
}
for(i=0;i<10000;i++){
a1 = rand() % list[a0].mam;
print_char(list[a0].letter[a1]);
a0=list[a0].letter[a1];
}printf("\n \n \n");
fclose(fp);
return 0;
}
int print_char(int n){
if(n==0){
printf("\n");
}
if(n==1){
printf(" ");
}
if((n>=2)&&(n<=27)){
printf("%c",n+95);
}
if(n==28){
printf("%c%c",-61,-96);
}
if(n==29){
printf("%c%c",-61,-89);
}
if(n==30){
printf("%c%c",-61,-88);
}
if(n==31){
printf("%c%c",-61,-87);
}
if(n==32){
printf("%c%c",-61,-86);
}
if(n==33){
printf("%c%c",-61,-76);
}
if(n==34){
printf("%c%c",-61,-94);
}
if(n==35){
printf("%c%c",-61,-85);
}
if(n==36){
printf("%c%c",-61,-82);
}
if(n==37){
printf("%c%c",-61,-81);
}
if(n==38){
printf("%c%c",-61,-71);
}
if(n==39){
printf("%c%c",-61,-69);
}
if(n==40){
printf("%c%c",-59,-109);
}
if(n==41){
printf("%c%c%c",-30,128,153);
}}