CSP认证 201409-3 字符串匹配

/*find函数用法:S1.find(S2)可以返回在S2中S1 第一次出现的位置,若没有则返回-1
S1.rfind(S2),从后往前找
find_first_of()找子串中某个字符最先出现的位置,不要求全匹配
find_last_of()子串中某个字符最后出现的位置,不要求全匹配
*/

#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

const int N = 110; 
string str;
int c,n;

string transform(string s)
{
	/*string res;
	for(auto c : s)
		res += tolower(c); //tolower函数将一个大写字符char变成其小写,若本来就是小写则不变 
	return res;*/
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] <= 'Z' && s[i] >= 'A') s[i] += 32;
	}
	return s;
}

int main()
{
	
	cin >> str;
	cin >> c;
	cin >> n;
	while(n--)
	{
		string str1;
		cin >> str1;
		if(c == 1)//大小写敏感 
		{
			if(str1.find(str) != -1) cout << str1 << endl;
		}
		else if(c == 0) //大小写不敏感 
		{
			string S = transform(str);
			string S1 = transform(str1);
			if(S1.find(S) != -1) cout << str1 << endl;
		}
	}
	return 0;	
} 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值