标签:
Vijos1425子串清除 题解
1 #include "iostream" 2 #include "cmath" 3 #include "cstdio" 4 #include "cstring" 5 #define maxN 10000010 6 7 using namespace std ; 8 char a[maxN], b[maxN], stack[maxN]; 9 int Lena, Lenb; 10 11 bool match ( int top )//匹配函数 12 { 13 14 for(int i = top, j = Lena ; i >= 1 && j >= 1 ; --i, --j) 15 { 16 if(a[j] != stack[i])return false ; 17 } 18 19 return true ; 20 21 } 22 23 int main ( ) 24 { 25 long long ans = 0 ; 26 scanf("%s%s", a + 1, b + 1); 27 Lena = strlen(a + 1); 28 Lenb = strlen(b + 1); 29 int top = 1 ; 30 for(int i = 1 ; i <= Lenb ; ++i ) 31 { 32 stack[top] = b[i]; 33 if(stack[top] == a[Lena] && top >= Lena && match(top)) 34 { 35 ans++; 36 top -= Lena; 37 } 38 top++; 39 } 40 printf("%I64d", ans); 41 return 0 ; 42 }
(完)
标签:
原文地址:http://www.cnblogs.com/shadowland/p/5870377.html