思路参考的这位大佬
https://blog.csdn.net/yiwaite/article/details/102530593
·读入函数思路与大佬类似。
·输出函数里求交集利用了一个记录文件访问次数的数组,每读入一个单词,包含该单词的文件访问次数+1,最后从0-n扫描文件,记录访问次数与单词数相等的文件。
·求文件行数并集开了100X100的visit数组,记录访问状态。另开一个100X101的Rows数组,Rows[i][j]代表文件i的第j个包含单词的行编号,另外Rows[i][100]来记录文件i符合条件的行的数目。因为要求按输入顺序输出,行号小的一定先输出,对每一个文件i对Rows[i]数组进行排序。
这里我直接调用的qsor函数。
但是最后一个测试点仍没通过,代码和提交记录留在这,欢迎各位大佬一起讨论,有进展随时更新。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DCN_SIZE 30011
#define ROW_LEN 50+1
#define WORD_NUM 10+1
#define WORD_LEN 50
#define ROW_NUM 100+1
#define FILE_NUM 100+1
typedef struct FlNode *PtFlNode;
struct FlNode{
int FlNum, RwSize, *Row;
PtFlNode Next;
};
struct HsNode{
char Word[WORD_LEN];
PtFlNode File;
} WdTable[DCN_SIZE];
typedef struct FlTblNode{
char FlName[WORD_NUM];
char Info[ROW_NUM][ROW_LEN];
} * FlList;
void w_gets(char *st){
char c;
int i = 0;
while((c=getchar())!='\n'){
st[i++] = c;
}
st[i] = 0;
}
int Hash(char*st){
int len = strlen(st), h = 0;
char *s = st + len - 6;
if(len<6)s=st;
while(*s){
h = (h << 1) + *s++ - 'a'; //左移位数大于1,后两个测试点会报错
}
h = h % DCN_SIZE;
while(WdTable[h].File&&strcmp(st