zoukankan      html  css  js  c++  java
  • 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;
                }
            }
        }
    }

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

  • 相关阅读:
    Vue 路由组件
    编写第一个JavaScript程序
    JavaScript 介绍
    JavaScript
    前台数据库
    cookie
    js date string parse
    判断时间大小 yyyy-MM-dd 格式
    正则表达式替换
    测试计时器
  • 原文地址:https://www.cnblogs.com/Elaine-DWL/p/6568286.html
Copyright © 2011-2022 走看看