BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
来源:互联网 发布:windows中的文件属性 编辑:程序博客网 时间:2024/05/17 02:53
Description
约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串, 约翰有一张“能量字符串表”,上面有M(1≤M≤100)个代表能量的字符串.每个字符串由不超过30个字体构成,同样不存在空字符串.一个奶牛的名字蕴含多少个能量字符串,这个名字就有多少能量.所谓“蕴含”,是指某个能量字符串的所有字符都在名字串中按顺序出现(不一定一个紧接着一个).
所有的大写字母和小写字母都是等价的.比如,在贝茜的名字“Bessie”里,蕴含有“Be”
“sI”“EE”以及“Es”等等字符串,但不蕴含“lS”或“eB”.请帮约翰计算他的奶牛的名字的能量.
Input
第1行输入两个整数N和M,之后N行每行输入一个奶牛的名字,之后M行每行输入一个能量字符串.
Output
一共N行,每行一个整数,依次表示一个名字的能量.
Sample Input
5 3
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont
INPUT DETAILS:
There are 5 cows, and their names are "Bessie", "Jonathan",
"Montgomery", "Alicia", and "Angola". The 3 good strings are "se",
"nGo", and "Ont".
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont
INPUT DETAILS:
There are 5 cows, and their names are "Bessie", "Jonathan",
"Montgomery", "Alicia", and "Angola". The 3 good strings are "se",
"nGo", and "Ont".
Sample Output
1
1
2
0
1
OUTPUT DETAILS:
"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains
both "nGo" and "Ont", Alicia contains none of the good strings, and
"Angola" contains "nGo".
1
2
0
1
OUTPUT DETAILS:
"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains
both "nGo" and "Ont", Alicia contains none of the good strings, and
"Angola" contains "nGo".
题解
模拟,常用字符的ASCII码还是要记住为好。
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> using namespace std; int n,m,l[1010],ct[1010]; char ch[1010][1010],a[110]; void init() { scanf("%d%d",&n,&m); int i; for(i=1;i<=n;i++) {scanf("%s",ch[i]); l[i]=strlen(ch[i]); } } void doit() { scanf("%s",a); int i,j,k,ll; ll=strlen(a); for(i=1;i<=n;i++) {j=0,k=0; while(j<l[i]&&k<ll) {if(ch[i][j]<'a') ch[i][j]=(char)ch[i][j]+32; if(a[k]<'a') a[k]=(char)a[k]+32; if(ch[i][j]==a[k]) {j++; k++;} else j++; } if(k==ll) ct[i]++; /*for(j=0;j<l[i];j++) printf("%c",ch[i][j]); printf("\n");*/ } } int main() { init(); int i; for(i=1;i<=m;i++) doit(); for(i=1;i<=n;i++) printf("%d\n",ct[i]); return 0; }
0 0
- BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
- BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
- BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
- bzoj 1622: [Usaco2008 Open]Word Power 名字的能量
- 暴力遍历-BZOJ-1622- [Usaco2008 Open]Word Power 名字的能量
- bzoj1622 [Usaco2008 Open]Word Power 名字的能量
- [BZOJ1622] [Usaco2008 Open]Word Power 名字的能量
- bzoj1622【Usaco2008 Open】Word Power 名字的力量
- BZOJ 1604: [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
- BZOJ 1604 [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居 Treap
- bzoj 1604: [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
- BZOJ 1604 [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
- BZOJ 1604: [Usaco2008 Open]Cow Neighborhoods
- 并查集+Set-BZOJ-1604-[Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
- 麻烦的DP-BZOJ-1605-[Usaco2008 Open]Crisis on the Farm 牧场危机
- 【bzoj 1604】: [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居 set+并查集
- bzoj 1604: [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居(set+并查集)
- BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口
- IOS 5 6 7适配
- UVA 12295 Optimal Symmetric Paths (spfa + 记忆化搜索)
- 数据结构复习(在新位置上插入元素)
- poj 1180 Batch Scheduling 斜率优化dp
- 学习是为了找工作?
- BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
- undefined reference to libiconv_open ext/iconv/.libs/iconv.o by install phpsource
- 使用this调用本类中的属性
- Hibernate多对多@ManyToMany及多对一@ManyToOne学习
- Linux下memcached安装和启动方法
- 客户端Cookie的设置——可完成记住密码的操作
- 使用this调用构造方法
- 韩语学习之第一课
- 模板类与类模板、函数模板与模板函数等的区别