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

#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