-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacm.cpp
More file actions
92 lines (92 loc) · 2.42 KB
/
acm.cpp
File metadata and controls
92 lines (92 loc) · 2.42 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// 求子串
char *substr(char *strdest, char *strsrc, int nindex, int ncount) {
for(int i=0;i<ncount;i++) {
*(strdest+i)=*(strsrc+nindex+i);
}
strdest[ncount]='\0';
return strdest;
}
int main(int argc, char const *argv[]) {
int m[500] = {0}; // 存放随机数据
int mark[500] = {0}; // 存放随机后的序列化数据
int len = 0; // 文件长度
char data[55000]; // 文件中的数据
int index_l[4000] = {0}; // < 在data的位置索引
int index_r[4000] = {0}; // > 在data的位置索引
char first[500][200]; // 存放第一个字段
char second[500][200]; // 第二个字段
char third[500][200]; // 第三个字段
FILE * f; // 文件指针
srand((int)time(0));
for (int i = 0; i < 500; ++i) {
m[i] = rand()%500;
}
// 打开文件,初始化len,data
if ((f = fopen("danci.txt","r")) != NULL) {
fseek(f,0L,SEEK_END);
len = ftell(f);
printf("Lenght of file is %d\n", len);
fseek(f,0L,SEEK_SET);
fread(data,sizeof(char),len,f);
fclose(f);
}
// number_l: < 的个数
int number_l = 0;
int number_r = 0;
// 赋值index_l, index_r
for (int i = 0; i < strlen(data); ++i) {
if (data[i] == '<') {
index_l[number_l] = i;
number_l ++;
}
if (data[i] == '>') {
index_r[number_r] = i;
number_r ++;
}
}
// numbers: 总行数
int numbers = number_r/8;
// 存放字段值
for (int i = 0; i < 20; ++i) {
printf("%d,%d\n", index_l[i], index_r[i]);
}
for (int i = 0; i < numbers; ++i) {
substr(first[i], data, index_r[8*i+1]+1, index_l[8*i+2]-index_r[8*i+1]-1);
substr(second[i], data, index_r[8*i+3]+1, index_l[8*i+4]-index_r[8*i+3]-1);
substr(third[i], data, index_r[8*i+5]+1, index_l[8*i+6]-index_r[8*i+5]-1);
}
// 产生随机序列
for (int i = 0; i < numbers; ++i) {
if (mark[m[i]] == 0) {
mark[m[i]] = i;
}
else {
int j = mark[m[i]];
j = j+1;
if (j >= 500)
j = 0;
while(mark[j] != 0) {
j ++;
if (j >= numbers)
j = 0;
}
mark[j] = i;
}
}
// 存入文件
if ((f = fopen("cnew.md","w+")) != NULL ) {
fprintf(f, "<table class=\"affix\"><tr> <th>Root, Prefix or Suffix</th> <th>Meaning</th> <th>Examples</th>\n");
for (int i = 0; i < numbers; ++i) {
fprintf(f, "<tr class='ps0'><td>%s</td><td>%s</td><td>%s</td><tr>\n", first[mark[i]], second[mark[i]],third[mark[i]]);
}
fclose(f);
printf("Success,to beautiful you~\n");
}
getchar();
getchar();
return 0;
}