#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXBYTE
20
typedef struct _KeyInfo{
char KeyWord[MAXBYTE];
int F;
}KeyInfo_t;
typedef struct _filenode{
char Filename[MAXBYTE];
int Cnt;
KeyInfo_t *KIF;
}FileNode_t;
void SearchKeyWord(FileNode_t *fn, int cnt, char *keyword, int f)
{
int i, j;
for (i = 0; i < cnt; i ++)
{
for (j = 0; j < fn[i].Cnt; j ++)
{
if (!strcmp(fn[i].KIF[j].KeyWord, keyword))
{
if (fn[i].KIF[j].F == f)
{
printf("%s ", fn[i].Filename);
}
}
}
}
printf("\n");
}
int main(void)
{
int i, j, doc_Cnt;
scanf("%d", &doc_Cnt);
FileNode_t *FN = (FileNode_t *)malloc(sizeof(FileNode_t)*doc_Cnt);
for (i = 0; i < doc_Cnt; i ++)
{
scanf("%s", FN[i].Filename);
scanf("%d", &FN[i].Cnt);
FN[i].KIF = (KeyInfo_t *)malloc(sizeof(KeyInfo_t)*FN[i].Cnt);
for (j = 0; j < FN[i].Cnt; j ++)
{
scanf("%s", FN[i].KIF[j].KeyWord);
scanf("%d", &FN[i].KIF[j].F);
}
getchar();
}
int Search_Cnt, F;
char keyword[MAXBYTE];
scanf("%d", &Search_Cnt);
for (i = 0; i < Search_Cnt; i ++)
{
scanf("%s", keyword);
scanf("%d", &F);
printf("> ");
SearchKeyWord(FN, doc_Cnt, keyword, F);
}
for (i = 0; i < doc_Cnt; i ++)
{
free(FN[i].KIF);
}
free(FN);
}
没有加检测错误的代码,还有你那个“频率从小到大排列”我还是闹不明白,明明是频率T怎么又要排呀,汗一下。。。