Hdu Excuses, Excuses! 字符串处理 map应用
2013-07-27 15:43
260 查看
给出多组字符串,拿字符串里的单词去比较题目给出的keyword,哪个字符串里存在keyword里的单词最多,就输出,若有多个满足,输出它们
用map,不得不说map真的很神奇
代码:
用map,不得不说map真的很神奇
代码:
#include <iostream> #include <cstring> #include <map> #include <cmath> #include <stack> #include <vector> #include <algorithm> #include <stdio.h> #include <string> using namespace std; struct node { char str[100]; int num; }a[25]; bool cmp(node a,node b) { return a.num>b.num; } int main() { int n,m,cas=1; while(scanf("%d%d",&n,&m)!=EOF) { memset(a,0,sizeof(a)); map<string,int>mp; string s; for(int i=0;i<n;i++) { cin>>s; mp[s]=1; } getchar(); for(int i=0;i<m;i++) { gets(a[i].str); int l=strlen(a[i].str); string w=""; char b[100]; strcpy(b,a[i].str); for(int j=0;j<l;j++) { if(b[j]>='A' && b[j]<='Z') { b[j]+=32; } } for(int j=0;j<l;j++) { if(b[j]>='a'&&b[j]<='z') w+=b[j]; else { map<string,int>::iterator it; it=mp.find(w); if(it!=mp.end()) a[i].num++; w=""; } } } sort(a,a+m,cmp); int vv=a[0].num; printf("Excuse Set #%d\n",cas); cas++; for(int i=0;i<m;i++) { if(a[i].num==vv) { printf("%s\n",a[i].str); } else break; } printf("\n"); } return 0; }
相关文章推荐
- JS常用字符串处理方法应用总结
- uva 409 Excuses, Excuses!(字符串处理)
- guava处理字符串与List之间,字符串与map之间的转换
- UVA ~ 1596 ~ Bug Hunt (字符串处理 + map)
- COJ: Languages(字符串处理、map映射)
- 8.1.15 不变字符串String处理的应用
- 关于字符串处理的应用扩展
- 利用Set List Map集合的特点处理重复字符串
- StringUtils.java应用,非常不错的字符串处理类(zz)
- 字符串分割处理,strstr函数应用
- JS常用字符串处理方法应用总结
- R语言空间换时间算法、Hash键值对在字符串处理中的应用
- 问题 C: 魔法串(字符串处理||01标志量的的灵活应用)
- JSONObject.fromObject 转换JSON字符串Map时间处理的问题
- SQL开发应用实例存储过程——各种字符串分拆处理函数
- Map字符串类型去掉空格处理
- Tangled in Cables(Kruskal+map容器处理字符串)
- poj1598Excuses, Excuses!(字符串处理)
- hive表中json字符串转map的处理
- map根据值排序,字典排序,读入带空格的字符串处理