hdu 4150 Powerful Incantation
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=4150
Powerful Incantation
Description
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 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.
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
由于模式串很短所以直接暴力即可。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::map;
using std::pair;
using std::vector;
using std::multimap;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
typedef unsigned long long ull;
char text[N], pat[];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) {
scanf("%s %s", text, pat);
char *p = text;
int ans = , len = strlen(pat);
while (p = strstr(p, pat)) {
ans++;
p += len;
}
printf("%d\n", ans);
}
return ;
}
hdu 4150 Powerful Incantation的更多相关文章
- 【HDU 4150】Powerful Incantation
题 题意 给你s1,s2两个字符串,求s1中有多少个s2 代码 #include<stdio.h> #include<string.h> int t,len1,len2,pos ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
- HDU 5115 Dire Wolf 区间dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5115 Dire Wolf Time Limit: 5000/5000 MS (Java/Others ...
- hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 1044 Collect More Jewels(BFS+DFS)
Collect More Jewels Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1052 Tian Ji -- The Horse Racing(贪心)(2004 Asia Regional Shanghai)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Ch ...
- hdu 1045 Fire Net(最小覆盖点+构图(缩点))
http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS Memory Limit:32768KB ...
- hdu 4499 Cannon dfs
Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...
- HDU 1045(Fire Net)题解
以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] 给定大小的棋盘中部分格子存在可以阻止互相攻击的墙,问棋盘中可以放置最多多少个可以横纵攻击炮塔. [题目分析] 这题本来在搜索专题 ...
随机推荐
- log4
<?xml version="1.0"?> <configuration> <configSections> <section name= ...
- 互联网+医疗(FW)
http://www.yn.xinhuanet.com/health/2015-06/05/c_134300133.htm 互联网+医疗 让合适的病人找合适的医生 www.yn.xinhuanet.c ...
- GLSL 中的光照计算
理论知识转载地址:http://blog.csdn.net/ym19860303/article/details/25545933 1.Lambert模型(漫反射) 环境光: Iambdiff = K ...
- webview渲染流程
文档标记说明 ################# 消息边界 +++++++++++++++++ 区域分隔 $$$$$$$$$$$$$$$$$ 线程边界 ~~~~~~~~~~~~~~~~~ 进程边界 - ...
- Leetcode008. String to Integer (atoi)
/* improvement on dealing with overflow accroding to this: * https://discuss.leetcode.com/topic/5745 ...
- python线程使用场景 多线程下载
http://blog.xiayf.cn/2015/09/11/parallelism-in-one-line http://python.jobbole.com/84327/ http://www. ...
- 多行文字垂直居中(完美兼容chrome firefox IE6 7 8 9)
在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在这里我还要啰嗦两句,CSS中 ...
- std::cout彩色输出
Mac OS效果 Windows 效果 想写这个东西其实是因为最近要写个命令行的工具,但是有个问题是什么呢?就是传统的那个黑漆漆的窗口看起来很蛋疼.并且完全看不到重点,于是就想起 来这么一个东西.相对 ...
- LLVM language 参考手册(译)(3)
可见性模式(Visibility Styles) 所有全局变量和函数具有以下的可见性模式之一: “default” - Default style 在那些使用ELF object file格式的平台( ...
- 三国塔防游戏android源码
三国塔防游戏源码,这个游戏源码比较完整的,因为上传有20M限制,把代码工程包分开了,主文件是TFGame,其他res大家按照安卓包加进去就行,欢迎下载并交流 ,大家可以参考一下吧.<ignore ...