hdu 12881 Jumble Match

Jumble Match
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 14, Accepted users: 13
Problem 12881 : No special judgement
Problem 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
cat
10 act canto chest colt crest eject hutch scant tact track
10 bitch cat civet cotta cut evict notch stack tic tuck
2 cant chert
0
cat_
10 act canto chest colt crest eject hutch scant tact track
10 bitch cat civet cotta cut evict notch stack tic tuck
2 cant chert
0
Australian Programming Contest! 2013
c_t_
10 act canto chest colt crest eject hutch scant tact track
10 bitch cat civet cotta cut evict notch stack tic tuck
2 cant chert
0
.
Sample Output
Test 1: 4
Test 2: 6
Test 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 __int64

using 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;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值