当前位置:网站首页>*3-4 CCF 2014-09-3 String matching
*3-4 CCF 2014-09-3 String matching
2022-08-09 14:51:00 【Leaf Xiao Bai】
题目描述


源代码
#include<iostream>
#include<cstring>
using namespace std;
const int N = 100;
//CCF 2014-09-3 字符串匹配
int main()
{
char key[N + 1], s[N + 1], lowkey[N + 1], lower[N + 1];
int opt, n;
cin >> key >> opt >> n;
strcpy(lowkey, key);
strlwr(lowkey);
for (int i = 1; i <= n; i++)
{
cin >> s;
if (opt == 0)//大小写无关
{
strcpy(lower, s);
strlwr(lower);
if (strstr(lower,lowkey))
{
cout << s << endl;
}
}
else
{
if (strstr(s, key))
cout << s << endl;
}
}
return 0;
}
关于这题
strcpy 字符串拷贝
strlwr 全变成小写
定义:strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串.如果是,则该函数返回str2在str1中首次出现的地址;否则,返回NULL.
char str2 = “cdef”;
char str1 = “abcdefgh”;
则通过函数,将返回
strstr(str1,str2) = cdefgh;
如果str1不包含有str2.
char str2 = “cxef”;
char str1 = “abcdefgh”;
则通过函数,将返回
strstr(str1,str2) = NULL;
边栏推荐
猜你喜欢
随机推荐
*4-1 CCF 2014-12-1 Access Control System
ELK部署
shell课程总结
display:inline-block 什么时候不会显示间隙?
C语言 最大公约数,最小公倍数(详细注释代码 一次解决)
除了开心麻花,中国喜剧还有什么?
shell课程总结
RHCE课程总结
RHCE课程总结
#23-5 OJ 86 杨辉三角形
C语言中的 递归问题 以及将递归改写成非递归。(解析常见的几个递归题目及代码) 求阶乘、求斐波那契、汉诺塔、
小程序模板制作流程,小程序模板制作方便快捷
*2-1 OJ 254 翻煎饼
元气森林“0糖”背后的百亿推手
Kubernetes资源编排系列之三: Kustomize篇
测试研发的人数科学比例
递归实现汉诺塔问题
Xshell建立SSH隧道连接
Difference between apt-get install and pip install
RHCE Course Summary









