Describe
http://www.lydsy.com/JudgeOnline/problem.php?id=1622
Give multiple text strings and pattern strings to find out how many pattern strings are in each text string.
Analysis
Direct violence ...
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn= ++5, maxm= -+5, maxl= -+5;5 intn,m;6 intT[MAXN][MAXN],P[MAXM][MAXL];7 CharC;8 CharS[MAXN];9InlineBOOLMatchintXinty) {Ten intl1=t[x][0],l2=p[y][0],i,j; One for(i=1, j=1; i<=l1&&j<=l2;i++)if(T[x][i]==p[y][j]) J + +; A returnJ>L2; - } - intMain () { thescanf"%d%d",&n,&m); - for(intI=1; i<=n;i++){ -scanf"%s", s+1);intL=strlen (s+1); s[n][0]=l; - for(intj=1; j<=l;j++) t[i][j]=s[j]>='a'&&s[j]<='Z'? s[j]-'a': s[j]-'A'; + } - for(intI=1; i<=m;i++){ +scanf"%s", s+1);intL=strlen (s+1); p[i][0]=l; A for(intj=1; j<=l;j++) p[i][j]=s[j]>='a'&&s[j]<='Z'? s[j]-'a': s[j]-'A'; at } - for(intI=1; i<=n;i++){ - intans=0; - for(intj=1; j<=m;j++)if(Match (I,J)) ans++; -printf"%d\n", ans); - } in return 0; -}
View Code
1622: [Usaco2008 Open]word Power name Energy time limit:5 Sec Memory limit:64 MB
submit:496 solved:253
[Submit] [Status] [Discuss] DescriptionJohn wanted to calculate the energy of his N (1≤n≤1000) cow's name. Each cow's name is made up of no more than 1000 characters, and no name is an empty string, and John has an "energy strings table" with a string of M (1≤m≤100) representing energy. Each string consists of no more than 30 fonts, and there is no empty string. How many energy strings a cow's name contains, and how much energy this name has. The so-called "implication" means that all the characters of an energy string appear sequentially (not necessarily one after the other) in the name string. all uppercase and lowercase letters are equivalent. For example, in Bessie's name "Bessie", there was "be.""SI" "EE" and "Es" and so on string, but does not contain "LS" or "EB". Please help John calculate the energy of his cow's name. InputEnter two integers n and m in line 1th, then enter the name of a cow for each row of n rows, and then enter an energy string for each row of m rows. OutputTotal n rows, one integer per line, followed by the energy of a name. Sample Input5 3
Bessie
Jonathan
Montgomery
Alicia
Angola
Se
Ngo
Ont
INPUT DETAILS:
There is 5 cows, and their names is "Bessie", "Jonathan",
"Montgomery", "Alicia", and "Angola". The 3 good strings is "se",
"NGo", and "Ont".
Sample Output1
1
2
0
1
OUTPUT DETAILS:
"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains
Both "NGo" and "Ont", Alicia contains none of the good strings, and
"Angola" contains "NGo".
Hintsource
Silver
Bzoj_1622_[usaco2008_open]_word_power_ Name of energy _ (character match _ violence)