17.04.29 Powerful Incantation
来源:互联网 发布:yy软件怎么上马甲 编辑:程序博客网 时间:2024/06/05 07:37
Powerful Incantation
HDU - 4150Some 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 easily.
After consulted one hundred and eight thousand Magic Books, james0zan find a way 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 be calculated by the times the “magic index” appearance in the incantation. Notice that if two “magic index” overlapped, the power only should be calculated once. And we just want the incantation more powerful. That is to say, if the “magic index” is “aa”, the power of incantation “aaaa” is 2(“aa”+”aa”), not 1(“a”+”aa”+”a”) or 3.
After consulted one hundred and eight thousand Magic Books, james0zan find a way 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 be calculated by the times the “magic index” appearance in the incantation. Notice that if two “magic index” overlapped, the power only should be calculated once. And we just want the incantation more powerful. That is to say, if the “magic index” is “aa”, the power of incantation “aaaa” is 2(“aa”+”aa”), not 1(“a”+”aa”+”a”) or 3.
Input
The first line is an integer t (t<=30), the number of test cases. Each of the next t lines contains two strings, represent the incantation (length<=10^6) and the “magic index” (length<=5). Every char in the incantation and the magic index is lowercase.
Output
For each test case you should output the power of the incantation.
Sample Input
3
aaaa aa
bsdjfassdiifo sd
papapapapapapap ap
Sample Output
2
2
7
可以说是非常水了。读个字符串,然后再读要查找的串,选0到strlen-1为起始点,再在内层循环逐个比较字符,这里如果有一个字符不一样就break,记有几个字符一样,如果和查找串的长度一样把外层循环的计数器放在当前找到的串的最后一位(因为不能重叠)。一遍过没什么好说。
#include<stdio.h>#include<string.h>int main(){ int t; scanf("%d\n",&t); while(t--) { char ss[1000002],sss[6]; scanf("%s %s",ss,sss); //printf("%c %c\n",ss[3],sss[1]); int i,summ=0; for(i=0;i<=strlen(ss)-1;i++) { int j,sum=0; for(j=0;j<=strlen(sss)-1;j++) { if(ss[i+j]==sss[j])sum++; else break; } if(sum==strlen(sss)) { i=i+j-1; summ++; } } printf("%d\n",summ); } return 0;}
0 0
- 17.04.29 Powerful Incantation
- HDU 4150 Powerful Incantation
- HDU 4150 Powerful Incantation
- hdu 4150 Powerful Incantation
- 【字符串】hdu4150 Powerful Incantation
- hdu 4150 Powerful Incantation
- Powerful Incantation(HDU 4150)
- hdu 4150 Powerful Incantation 暴力||KMP
- 2011百校联动“菜鸟杯”程序设计公开赛 &&Powerful Incantation
- 【HDU 4150】Powerful Incantation —— 字符串匹配
- HDU 4150 Powerful Incantation / Codeforces 625B - War of the Corporations
- 【JZOJ4473】Incantation Solution
- Most Powerful
- Powerful Google Maps APIs
- Ten Powerful Linux Commands
- ELM327 Powerful Scan Tool
- zoj 3471 Most Powerful
- ZOJ - 3471 Most Powerful
- win7下安装tornado以及python环境
- redis -- 过期 淘汰 事务原子机制
- The basics of OFDM ——Fourier Transform
- 对线程的新的认识.线程句柄和线程ID
- maven的核心概念&Maven仓库管理
- 17.04.29 Powerful Incantation
- BZOJ 4810([Ynoi2017]由乃的玉米田-莫队)
- Redis之字典
- HDU 1269 迷宫城堡(tarjan强联通分量)
- find the most comfortable road (并查集 + 暴力)
- Linux下实现Oracle11g静默安装教程
- 【洛谷P3370】【NOIP2013】 火柴排队
- 解决Linux系统下安装redis make出错的问题
- Java运算符口诀