UVA409strstr()函数
来源:互联网 发布:计算介质热量软件 编辑:程序博客网 时间:2024/05/29 13:51
这题可以用strstr()函数做也可以不用,贴上不用的,用strstr时注意单词不能被包含在一个更长的单词里面,
包含文件:string.h
函数名: strstr
函数原型:extern char *strstr(char *str1, const char *str2);
语法:* strstr(str1,str2)
str1: 被查找目标 string expression to search.
str2: 要查找对象 The string expression to find.
返回值:若str2是str1的子串,则先确定str2在str1的第一次出现的位置,并返回此位置到str1末尾的所有字符;如果str2不是str1的子串,则返回NULL。(注:若想返回str2在str1第一次出现的位置,不是这个函数)
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cctype>#include<string>#include<map>#include<set>#include<cmath>#include<vector>#include<queue>#include<stack>using namespace std;char key[25][25];char excuse[25][75];int main(){ int k,e; int cas=0; while(cin>>k>>e) { getchar(); cas++; for(int i=0;i<k;i++) gets(key[i]); for(int i=0;i<e;i++) gets(excuse[i]); int a[25]; memset(a,0,sizeof(a)); int amax=0; for(int i=0;i<e;i++) { char c[100],len=0; for(int j=0;j<strlen(excuse[i]);j++) { if(isalpha(excuse[i][j])) { c[len++]=excuse[i][j]; c[len-1]=tolower(c[len-1]); } else { c[len]='\0'; for(int x=0;x<k;x++) if(strcmp(c,key[x])==0) a[i]++; len=0; } /*if(isalpha(excuse[i][j])) { char c[100]; int len=0; for(;j<strlen(excuse[i]);j++) { if(isalpha(excuse[i][j])) { c[len++]=excuse[i][j]; c[len-1]=tolower(c[len-1]); } else break; } c[len]='\0'; for(int x=0;x<k;x++) if(strcmp(c,key[x])==0) a[i]++; }*/ } amax=max(amax,a[i]); } printf("Excuse Set #%d\n",cas); for(int i=0;i<e;i++) if(a[i]==amax&&amax!=0) printf("%s\n",excuse[i]); cout<<endl; } return 0;}
0 0
- UVA409strstr()函数
- 组函数(聚合函数),分组函数
- 函数(-)
- JavaScript之 ------ 函数(一般函数、动态函数、匿名函数)
- python学习--函数(调用函数、定义函数、递归函数)
- NET函数(字符串函数)
- 生成函数(母函数)
- select()函数、poll()函数
- 生成函数(母函数)
- 生成函数(母函数)
- 母函数(生成函数)
- 母函数(生成函数)
- select()函数、poll()函数
- 递归函数(FIBNACCI函数)
- 单行函数(数值函数)
- 母函数(生成函数)
- 母函数(生成函数)
- Lambda 函数 (匿名函数)
- 1050. String Subtraction (20)
- Spring MVC笔记
- [.NET/C#][Win7 x64]基于Windows Media Encoder 的屏幕录像
- cleanmymac如何将文件添加到忽略列表中
- PAT (Basic Level) Practise (中文)1019. 数字黑洞 (20)
- UVA409strstr()函数
- Callabble和Future
- Mac下安装Pillow
- 乌云白帽子大会感受
- 关于在项目里使用jquery的ajax函数。
- open/close函数的使用
- Eclipse luna + Maven 3.2.5 +JDK 1.7 +Tomcat 7.0 从SVN下载maven项目及其构建、运行(2015.7.20)
- Linux文件类型分类
- Intent和PendingIntent的区别