HDU 4150 Powerful incantation

Source: Internet
Author: User

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=4150

Powerful incantationdescription

Some Dangerous witches invaded the garden city! As a righteous magician, James0zan want to find the most powerful incantation so he can beat those dangerous witches Easil Y.
After consulted one hundred and eight thousand Magic Books, James0zan find a-to-calculate the power of an incantation. There is a very short incantation called "Magic Index" which contains the magic power, and each incantation ' s power can B e calculated by The Times the ' Magic Index ' appearance in the incantation. Notice that if both "magic Index" overlapped, the power only should is calculated once. And we just want the incantation more powerful. That was to say, if the ' Magic Index ' is ' AA ', the power of incantation "AAAA" is 2 ("AA" + "AA") and not 1 ("a" + "AA" + "a") or 3.

Input

The first line was an integer T (t<=30), the number of test cases. Each of the next T lines contains the strings, represent the incantation (length<=10^6) and the "Magic Index" (LENGTH&L t;=5). Every char in the incantation and the-the Magic index is lowercase.

Output

For each test case you should output the power of the incantation.

3
AAAA AA
Bsdjfassdiifo SD
PAPAPAPAPAPAPAP AP

Sample Input

2
2
7

Because the pattern string is very short, direct violence can be.

1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <map>8 usingstd::cin;9 usingstd::cout;Ten usingStd::endl; One usingStd::find; A usingStd::sort; - usingStd::map; - usingstd::p air; the usingstd::vector; - usingStd::multimap; - #definePB (E) push_back (e) - #defineSZ (c) (int) (c). Size () + #defineMP (A, b) Make_pair (A, B) - #defineAll (c) (c). Begin (), (c). End () + #defineITER (c) Decltype ((c). Begin ()) A #defineCLS (arr,val) memset (arr,val,sizeof (arr)) at #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) - #defineRep (i, n) for (int i = 0; i < (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) - Const intN =1000011; -typedef unsignedLong Longull; - CharText[n], pat[Ten]; in intMain () { - #ifdef LOCAL toFreopen ("In.txt","R", stdin); +Freopen ("OUT.txt","w+", stdout); - #endif the     intT; *scanf"%d", &t); $      while(t--) {Panax Notoginsengscanf"%s%s", text, Pat); -         Char*p =text; the         intAns =0, Len =strlen (PAT); +          while(P =STRSTR (P, Pat)) { Aans++; thep + =Len; +         } -printf"%d\n", ans); $     } $     return 0; -}
View Code

HDU 4150 Powerful incantation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.