当前位置:网站首页>*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;
边栏推荐
猜你喜欢
随机推荐
Xshell建立SSH隧道连接
*1-1 OJ 56 Hamming Distance
word编号和文本间距过大
C语言 交换两个变量(不创建临时变量) 代码详解
C语言 猜数字游戏 (含代码并详细注释)
* 3-3 cattle from rearranged
shell课程总结
vivo手机上的系统级消息推送平台的架构设计实践
RHCE课程总结
*5-1 CCF 2015-03-1 图像旋转
dpkg:错误:无法新建文件 ‘/var/lib/dpkg/info/format-new’: 没
From the Dutch flag problem to the optimization and upgrade of quick row
add-apt-repository命令详解
Jetpack Compose - remember, mutableStateOf, rememberSaveable
*3-3牛客网 重新排列
*3-4 CCF 2014-09-3 字符串匹配
RHCE课程总结
Bubble sort (detailed)
在Word中如何调整编号和文字之间的间距?
【视频编码学习】——变换的理解









