当前位置:网站首页>*3-4 CCF 2014-09-3 字符串匹配
*3-4 CCF 2014-09-3 字符串匹配
2022-08-09 13:31:00 【叶萧白】
题目描述


源代码
#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;
边栏推荐
猜你喜欢
随机推荐
汇编语言学习(九)
C语言 三子棋(含完整 代码详解)
Jetpack Compose——Image(图片)的使用
Thinking about oracle financial data authority
远程控制软件-向日葵
VNet
KMP方法
GridContainer of openharmony container component
现实版商战:“武功再高,也怕菜刀”
关于舵机的漂移与不听指挥乱动的问题
易语言获取cookie
记一次 ERROR scheduler.AsyncEventQueue: Dropping event from queue shared导致OOM
汇编语言学习(六)课程设计一
用asp.net基于C#编写简单登录注册界面(访问数据库)
Where to go to IOE-EBS
理解redis,一篇就够
Spark Sql之union
汇编语言学习(八)
【面试高频题】可逐步优化的链表高频题
C语言 求一个整数存储在内存中的二进制中1的个数(多种方法详解)









