csp认证201409-3字符串匹配(100分)【刷题】

本文介绍了一种简单的字符匹配算法,并实现了大小写不敏感的字符串搜索功能。通过使用C++标准库,该程序能够有效地处理字符串匹配任务,无论是否考虑字母的大小写。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int type,n;
void bigTosmall(string &s){
    int len=s.size();
    for(int i=0;i<len;i++){
        if(s.at(i)>=65&&s.at(i)<91){
            s.replace(s.begin()+i,s.begin()+i+1,1,s.at(i)+32);//大写转小写 
        }
    }
}
int main(){
    string aim;
    cin>>aim>>type>>n;//aim是需要查找的字符串  type=1字符串敏感   n是测试数目 
    vector<string> vec;
    string temp;
    while(n--){
        cin>>temp;
        vec.push_back(temp);
    }
    vector<string>::iterator ite=vec.begin();
    if(type==1){//大小写敏感 
        for(;ite<vec.end();ite++){
            if((*ite).find(aim)!=string::npos){
                cout<<*ite<<endl;
            }
        }    
    }
    else{//大小写不敏感 全部转为小写再进行比较 
        bigTosmall(aim); 
        for(;ite<vec.end();ite++){
            string s=*ite;
            bigTosmall(*ite);
            if((*ite).find(aim)!=string::npos){
                cout<<s<<endl;
            }
        }
    }
}

就是很简单的字符匹配  还有大小写转换  

转载于:https://www.cnblogs.com/Elaine-DWL/p/6568286.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值