Regular Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1645 Accepted Submission(s): 446
(0|9|7) (5|6) (2) (4|5)
Above regular expression matches 4 digits:The first is one of 0,9 and 7. The second is one of 5 and 6. The third is 2. And the fourth is one of 4 and 5. The above regular expression can be successfully matched to 0525, but it cannot be matched to 9634.
Now,giving you a regular expression like the above formula,and a long string of numbers,please find out all the substrings of this long string that can be matched to the regular expression.
#include <stdio.h>
#include <string.h>
#include <bitset>
using namespace std;
const int N=1005;
bitset<N> ans;
bitset<N> dic[N];
char str[5000005];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
{
int k;
scanf("%d",&k);
for(int j=0;j<k;j++)
{
int tmp;
scanf("%d",&tmp);
dic[tmp].set(i);
}
}
getchar();
gets(str);
int len=strlen(str);
for(int i=0;i<len;i++)
{
ans=ans<<1;
ans.set(0);
ans=ans&dic[str[i]-'0'];
if(ans[n-1]==1)
{
char s=str[i+1];
str[i+1]='\0';
puts(str+i-n+1);
str[i+1]=s;
}
}
}
return 0;
}