就是简单的用strstr函数对字符串进行处理。
另解:暴力(就是用strstr函数对字符串进行处理)另解:暴力(普通的字符串处理 。关键是strstr函数):
#include<stdio.h>
#include<string.h>
struct Bing
{
char name[210];
int num;
}bing[510];
struct Web
{
char name[10010];
int num;
bool ok;
int a[4];
}web[1010];
int tot = 0;
int main()
{
int n, m;
while(scanf("%d",&n) != EOF)
{
for (int i=0; i<1010; ++i)
{
memset(web[i].name, 0, sizeof(web[i].name));
web[i].ok = false;
memset(web[i].a, -1, sizeof(web[i].a));
web[i].num = 0;
}
tot = 0;
for (int i=0; i<n; ++i)
{
scanf("%s", bing[i].name);
bing[i].num = i+1;
}
scanf("%d", &m);
for (int i=0; i<m; ++i)
{
scanf("%s", web[i].name);
web[i].num = i + 1;
int cnt = 0;
for (int j=0; j<n; ++j)
{
if (strstr(web[i].name, bing[j].name))
{
web[i].ok = true;
web[i].a[cnt++] = j;
if (cnt == 3)
break;
}
}
}
for (int i=0; i<m; ++i)
{
if (web[i].ok)
{
tot++;
printf("web %d:", web[i].num);
for (int j=0; j<3; ++j)
{
if (web[i].a[j] != -1)
{
printf(" %d", web[i].a[j] + 1);
}
}
printf("\n");
}
}
printf("total: %d\n", tot);
}
return 0;
}