FZU 1632 Word Power

 

Word Power

Time Limit:2sMemory limit:32M
Accepted Submit:131Total Submit:371

Farmer John wants to evaluate the quality of the names of his N (1 <= N <= 1000) cows. Each name is a string with no more than 1000 characters, all of which are non-blank.
He has created a set of M (1 <= M <= 100) 'good' strings (no longer than 30 characters and fully non-blank). If the sequence letters of a cow's name contains the letters of a 'good' string in the correct order as a subsequence (i.e., not necessarily all next to each other), the cow's name gets 1 quality point.
All strings is case-insensitive, i.e., capital letters and lower case letters are considered equivalent. For example, the name "Bessie" contains the letters of "Be", "sI", "EE", and "Es" in the correct order, but not "is" or "eB". Help Farmer John determine the number of quality points in each of his cow's names.

Input

There are multiple tests. For each test, there are three parts.
  • * Line 1: Two space-separated integers: N and M
  • * Lines 2..N+1: Line i+1 contains a string that is the name of the ith cow
  • * Lines N+2..N+M+1: Line N+i+1 contains the ith good string

Output

For each test, you should output following part.
* Lines 1..N+1: Line i+1 contains the number of quality points of the ith name

Sample Input

5 3
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont

Sample Output

1
1
2
0
1

Original: Summer Training Qualification II

 

 

暴力过的............欢迎提供更好的算法-______________________-

  1. #include <stdio.h>
  2. #include <string.h> 
  3. char cow[1001][1001],good[101][31];
  4. int point(char *a, char *b)//a<b
  5.       {int lena,lenb,i,j,k;
  6.         lena=strlen(a),lenb=strlen(b);
  7.         if(lena<lenb) return 0;
  8.         if(lena==lenb) if(strcmp(a,b)==0) return 1;else return 0;
  9.         k=0;
  10.         for(i=0;i<lenb;i++)
  11.             {
  12.             for(j=k;j<lena;j++)
  13.                 if(b[i]==a[j])
  14.                     {k=j+1;break;}
  15.             if(j==lena) return 0;
  16.             }
  17.         return 1;
  18.       }
  19. void lcase(char *a)
  20. {
  21.     int len=strlen(a)-1;
  22.     int i;
  23.     for(i=0;i<=len;i++)
  24.         if(a[i]>='A'&&a[i]<='Z') a[i]+=32;
  25. }
  26. int main()
  27. {int cn,gn,i,j,res;
  28.  while(scanf("%d%d",&cn,&gn)!=EOF)
  29.     {
  30.      getchar();
  31.      for(i=0;i<cn;i++)
  32.         gets(cow[i]),lcase(cow[i]);
  33.      for(i=0;i<gn;i++)
  34.          gets(good[i]),lcase(good[i]);
  35.      for(i=0;i<cn;i++)
  36.         {res=0;
  37.          for(j=0;j<gn;j++)
  38.             res+=point(cow[i],good[j]);
  39.          printf("%d/n",res);
  40.         }
  41.     }
  42. return 0;
  43. }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值