#include <iostream.h>
#include <fstream.h>
ifstream f("a.txt");
#define cin f
#include <string.h>
int fun(char *s,char *t)
{
int pos1,pos2,i;
pos2=0;
while(s[pos2]!='\0')
{
if(s[pos2]=='.')
{
if(s[pos2+1]=='c' && s[pos2+2]=='o' && s[pos2+3]=='m' && (s[pos2+4]=='\0' ||
s[pos2+4]=='/' || s[pos2+4]=='.'))
{
pos1=pos2-1;
while(s[pos1]!='.')
pos1--;
goto loop;
}
else if (s[pos2+1]=='n' && s[pos2+2]=='e' && s[pos2+3]=='t' && (s[pos2+4]=='\0' ||
s[pos2+4]=='/' || s[pos2+4]=='.'))
{
pos1=pos2-1;
while(s[pos1]!='.')
pos1--;
goto loop;
}
}
pos2++;
}
loop : for(i=0;i<pos2-pos1;i++)
t[i]=s[i+pos1];
t[pos2-pos1]='\0';
return 0;
}
struct Node
{
char url[100];
char value[30];
int w;
char keyword[100][30];
int key[100];
int r;
char hypervalue[100][30];
int flag;
}node[100];
int main()
{
int n,i,j,k,l,r;
int N=0;
int mm[100];
int pos[100];
char keyword[30];
cin>>n;
char hyper[100];
for(i=0;i<n;i++)
{
cin>>node[i].url;
fun(node[i].url,node[i].value);
cin>>node[i].w;
for(j=0;j<node[i].w;j++)
{
cin>>node[i].keyword[j];
node[j].key[i]=1;
}
cin>>node[i].r;
for(j=0;j<node[i].r;j++)
{
cin>>hyper;
fun(hyper,node[i].hypervalue[j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n && j!=i;j++)
{
for(k=0;k<node[j].r;k++)
if(strcmp(node[j].hypervalue[k],node[i].value)==0)
{
for(l=0;l<node[i].w;l++)
node[i].key[l]++;
}
}
}
cin>>k;
for(l=0;l<k;l++)
{
cin>>keyword;
N=0;
cout<<"Search results of keyword "<<keyword<<":"<<endl;
for(i=0;i<n;i++)
{
mm[i]=0;
pos[i]=i;
}
for(i=0;i<n;i++)
{
for(j=0;j<node[i].w;j++)
{
if(strcmp(node[i].keyword[j],keyword)==0)
{
mm[N]=node[i].key[j];
pos[N]=i;
N++;
break;
}
}
}
//cout<<N<<endl;
for(i=0;i<N;i++)
for(j=0;j<N-i-1;j++)
{
if(mm[j]<mm[j+1])
{
int temp=mm[j];
mm[j]=mm[j+1];
mm[j+1]=temp;
temp=pos[j];
pos[j]=pos[j+1];
pos[j+1]=temp;
}
}
for(i=0;i<N;i++)
{
for(j=4;j<strlen(node[pos[i]].url);j++)
cout<<node[pos[i]].url[j];
cout<<endl;
}
}
}
评论