题意 还是前面题目的意思; 只是需要解码
方法 不说了
#include<iostream> #include<stdio.h> #include<cstring> #include<algorithm> using namespace std; char str[5123456],sss[5123456],cha[1123]; struct date { date *next[27],*fail; bool fell; int sum; }tree[451234],*que[451234],*root; int tail,head,ptr; date *creat_node( ) { for( int i = 0; i < 26; i++ ) tree[ptr].next[i] = NULL; tree[ptr].fail = NULL; tree[ptr].fell = false; tree[ptr].sum = 0; return &tree[ptr++]; } void inint( ) { tail = head = ptr = 0; root = creat_node( ); } void insert( char *word ) { date *temp = root; while( *word ) { int num = *word - 'A'; if( temp->next[num] == NULL ) temp->next[num] = creat_node(); temp = temp->next[num]; word++; } temp->sum++; } void build_AC( ) { que[tail++] = root; while( tail > head ) { date *temp = que[head++]; for( int i = 0; i < 26; i++ ) if( temp->next[i] != NULL ) { if( temp == root ) temp->next[i]->fail = root; else temp->next[i]->fail = temp->fail->next[i]; temp->next[i]->fell = true; que[tail++] = temp->next[i]; } else { if( temp == root ) temp->next[i] = root; else temp->next[i] = temp->fail->next[i]; } } } int query( char *word ) { date *partten,*temp = root; int ans = 0; while( *word ) { int num = *word - 'A'; temp = temp->next[num]; partten = temp; while( partten != root ) { if( partten->fell ) { partten->fell = false; ans += partten->sum; } else break; partten = partten->fail; } word++; } return ans; } int main( ) { int T,N,i; scanf("%d",&T); while( T-- ) { scanf("%d",&N); inint(); for( i = 1; i <= N; i++ ) { scanf("%s",&cha); insert( cha ); } build_AC( ); scanf("%s",&str); int len = strlen( str ),num,k = 0; bool fell = false; for( i = 0; i < len; i++ ) { if( fell ) { if( str[i] - '0' >= 0 && str[i] - '0' <= 9 ) num = num*10 + ( str[i] - '0' ); else { while( num-- )sss[k++] = str[i]; fell = false; } continue; } if( str[i] == '[' ) { num = 0,fell = true; continue; } if( str[i] - 'A' >= 0 && str[i] - 'A' <= 25 ) sss[k++] = str[i]; } sss[k] = '\0'; int a = query( sss ); reverse( sss, sss + k ); a += query( sss ); printf("%d\n",a); } }