hdu 12881 Jumble Match

来源:互联网 发布:化妆品成分分析软件 编辑:程序博客网 时间:2024/05/17 07:31

Jumble MatchTime Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KBTotal submit users: 14, Accepted users: 13Problem 12881 : No special judgementProblem description

For the purpose of this problem, a word matches a pattern if a substring of the word matches the pattern. A pattern can contain letters (which should be matched explicitly) and underscores (which match any single letter). Finally, a pattern is considered matched if any jumble (permutation) of the pattern characters matches.
For example, the pattern cat matches words such as cat, scat, and cater because cat is a substring of the word. However, the pattern also matches words that contain permutations of cat as a substring, such as tacit, latch, and fact. And the pattern cat_ would match any word that contains a 4-character substring that is some permutation of the letters c, a, t, and any other letter, which would therefor match words such as track, cant, or crate.
Your task is to write a program that searches for a jumble match in a set of input words.



Input

Input will consist of specifications for a series of tests. Information for each test begins with a line containing a single string of length 1 <= n < 100 that specifies the pattern to search for. A pattern string consisting of a single dot terminates the input.
The lines following the pattern begin with an integer 1 <= n <= 10 that specifies the number of words on the line, followed by the words themselves, with a single space between items. Words are strings of alphabetic characters of length 1 < n < 20. A line with a word count of 0 ends the input for each test.



Output

Output should consist of one line for each test comprising the test number (formatted as shown) followed by a single space and the number of words in the input set that match the pattern.



Sample Input
cat10 act canto chest colt crest eject hutch scant tact track10 bitch cat civet cotta cut evict notch stack tic tuck2 cant chert0cat_10 act canto chest colt crest eject hutch scant tact track10 bitch cat civet cotta cut evict notch stack tic tuck2 cant chert0Australian Programming Contest! 2013c_t_10 act canto chest colt crest eject hutch scant tact track10 bitch cat civet cotta cut evict notch stack tic tuck2 cant chert0.
Sample Output
Test 1: 4Test 2: 6Test 3: 14

题意就是  给一个字符串ch  下面有若干行  每行有个数字n 以及n个字符串  这些字符串中包含ch中所以字符的字符串的个数  但是还有一个要求 就是 ch中有m个字符 则在下面的字符串中搜索时就要在连续的m个字符中搜索 如果字符串的长度小于m就不要搜索了

直接暴力得过

#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#define eps 1e-8#define op operator#define MOD  10009#define MAXN  100100#define FOR(i,a,b)  for(int i=a;i<=b;i++)#define FOV(i,a,b)  for(int i=a;i>=b;i--)#define REP(i,a,b)  for(int i=a;i<b;i++)#define REV(i,a,b)  for(int i=a-1;i>=b;i--)#define MEM(a,x)    memset(a,x,sizeof a)#define ll __int64using namespace std;int hash[30];int main(){//freopen("ceshi.txt","r",stdin);    char ch[110];    char in[15][25];    int count=1;    while(scanf("%s",ch))    {        if(ch[0]=='.')  break;        int len=strlen(ch);        int hash2[30];        MEM(hash,0);        int cnt=0;        for(int i=0;i<len;i++)        {            if(ch[i]>='a'&&ch[i]<='z')            {                int num=ch[i]-'a';                hash[num]++;            }//            if(ch[i]=='_')//                num++;        }        int sum=0;        int n;        while(scanf("%d",&n))        {           if(n==0)  break;           for(int i=0;i<n;i++)              scanf("%s",in[i]);           for(int i=0;i<n;i++)           {               int len2=strlen(in[i]);               if(strlen(in[i])<len)                continue;               else               {                   for(int j=0;j<=len2-len;j++)                   {                       MEM(hash2,0);                       for(int k=j;k<len+j;k++)                       {                           hash2[in[i][k]-'a']++;                       }                       int m;                       for(m=0;m<26;m++)                       {                           if(hash2[m]<hash[m])                           {//                               flag=1;                               break;                           }                       }                       if(m==26)                       {                           sum++;                           break;                       }                   }               }           }        }        printf("Test %d: %d\n",count++,sum);    }    return 0;}





0 0
原创粉丝点击