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