Skip to content

Commit 005a86b

Browse files
authored
Update main.c
修复判断胡不准备bug
1 parent f167286 commit 005a86b

File tree

1 file changed

+54
-29
lines changed

1 file changed

+54
-29
lines changed

phzlib_c/main.c

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,56 @@
22
#include "stdio.h"
33
#include "time.h"
44

5+
char cards_buf[2500000*21];
6+
int cards_buf_len = 0;
7+
void read_all(char* name)
8+
{
9+
FILE *fp = fopen(name, "rb");
10+
11+
memset(cards_buf, 0, sizeof(cards_buf));
12+
long long xiao;
13+
long long da;
14+
int tmp;
15+
cards_buf_len = 0;
16+
while(fscanf(fp, "%lld-%lld=%d\n", &da, &xiao, &tmp) != EOF)
17+
{
18+
char* cards = &cards_buf[cards_buf_len * 21];
19+
int i = 9;
20+
while (xiao > 0) {
21+
cards[i--] = (xiao % 10);
22+
xiao /= 10;
23+
}
24+
i = 19;
25+
while (da > 0) {
26+
cards[i--] = (da % 10);
27+
da /= 10;
28+
}
29+
cards[20] = tmp;
30+
++cards_buf_len;
31+
}
32+
}
33+
34+
int test_all(char* name)
35+
{
36+
read_all(name);
37+
38+
for (int i = 0; i < cards_buf_len; ++i)
39+
{
40+
int huxi = get_huxi(&cards_buf[i * 21]);
41+
int table_huxi = cards_buf[i * 21 + 20];
42+
if (huxi != table_huxi) {
43+
printf("胡息判断不对, 表%s, 序号%d, 计算%d,表%d\n", name, i+1, huxi, table_huxi);
44+
}
45+
}
46+
printf("test_all测试%s完成\n", name);
47+
return cards_buf_len;
48+
}
49+
550
void test() {
651
char cards[] = {
7-
1,2,2,1,2,1,2,1,0,1,
8-
1,2,2,1,0,0,0,2,0,0
52+
0,2,1,1,0,0,1,0,0,1,
53+
0,1,2,2,0,0,2,0,0,2
54+
955
};
1056
printf("胡息: %d\n", get_huxi(cards));
1157
}
@@ -20,35 +66,14 @@ void test_eye() {
2066

2167
int main()
2268
{
23-
char cards[] = {
24-
1,2,2,1,2,1,2,1,0,1,
25-
1,2,2,1,0,0,0,2,0,0
26-
};
27-
28-
char cards_eye[] = {
29-
1,1,2,1,2,1,1,0,0,0,
30-
1,2,2,1,0,0,2,1,1,1
31-
};
69+
//test();
70+
//getchar();
3271

3372
time_t begin = time(NULL);
34-
long long sum = 0;
35-
int k = 0;
36-
int count = 0;
37-
for (int i = 0; i < 10000*10000; ++i) {
38-
if (k) {
39-
sum += get_huxi(cards);
40-
count = count + 1;
41-
k = 0;
42-
}
43-
else {
44-
sum += get_huxi(cards_eye);
45-
count = count + 1;
46-
k = 1;
47-
}
48-
49-
}
50-
printf("胡息: %d\n", sum);
51-
printf("时间: %d\n", time(NULL) - begin);
73+
int count = test_all("table");
74+
75+
count += test_all("eye_table");
76+
printf("时间: %dS\n", time(NULL) - begin);
5277
printf("次数: %d万次\n", count/10000);
5378
getchar();
5479

0 commit comments

Comments
 (0)