| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
还有什么要注意的-蛮力字符串匹配#include<stdio.h>
#include<string.h>
int cmp(char a[],char b[],int k)//a[]是要匹配的字符串,b[]是原来字符串
{
int n,m,j,i,num=0;
m=strlen(a);n=k;
for(i=0;i<=n-m;i++)
{
j=0;
while(j<m&&a[j]==b[i+j])
j=j+1;
if(j==m){num++;continue;}
}
return num;
}
struct dictionary
{
char dict[17];
long dollar;
}d[1001];
void main()
{
long value=0;
int i,k,n,m;
int wordlenth[1000],num,j=0;
char desc[5001];
scanf("%d %d",&m,&n);
for(i=0;i<m;i++)
{
scanf("%s",d[i].dict);
scanf("%d",&d[i].dollar);
}
while(n--)
{
i=0;
while((desc[i]=getchar())!='.')// this while used to input the description
i++;
k=i;
for(i=0;i<m;i++)
{
value+=cmp(d[i].dict,desc,k)*d[i].dollar;
}
printf("%d\n",value);
value=0;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator