• ccf 字符串匹配


    问题描述
    试题编号: 201409-3
    试题名称: 字符串匹配
    时间限制: 1.0s
    内存限制: 256.0MB
    问题描述:
    问题描述
      给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行。你的程序还需支持大小写敏感选项:当选项打开时,表示同一个字母的大写和小写看作不同的字符;当选项关闭时,表示同一个字母的大写和小写看作相同的字符。
    输入格式
      输入的第一行包含一个字符串S,由大小写英文字母组成。
      第二行包含一个数字,表示大小写敏感的选项,当数字为0时表示大小写不敏感,当数字为1时表示大小写敏感。
      第三行包含一个整数n,表示给出的文字的行数。
      接下来n行,每行包含一个字符串,字符串由大小写英文字母组成,不含空格和其他字符。
    输出格式
      输出多行,每行包含一个字符串,按出现的顺序依次给出那些包含了字符串S的行。
    样例输入
    Hello
    1
    5
    HelloWorld
    HiHiHelloHiHi
    GrepIsAGreatTool
    HELLO
    HELLOisNOTHello
    样例输出
    HelloWorld
    HiHiHelloHiHi
    HELLOisNOTHello
    样例说明
      在上面的样例中,第四个字符串虽然也是Hello,但是大小写不正确。如果将输入的第二行改为0,则第四个字符串应该输出。
    评测用例规模与约定
      1<=n<=100,每个字符串的长度不超过100。
     1 #include<bits/stdc++.h>
     2 #include<algorithm>
     3 #include<iostream>
     4 #include <iostream>
     5 #include <algorithm>
     6 #include <vector>
     7 #include <functional>
     8 #include <cctype>
     9 using namespace std;
    10 string s1,s2;
    11 int n;
    12 void solve(string &s)
    13 {
    14     int l=s.size();
    15     for(int i=0;i<l;i++)
    16     {
    17         if(s[i]>='A'&&s[i]<='Z') s[i]=s[i]-'A'+'a';
    18     }
    19 }
    20 int main()
    21 {
    22   // freopen("in.txt","r",stdin);
    23     int flag;
    24     while(cin>>s1){
    25         scanf("%d",&flag);
    26         if(flag){
    27              scanf("%d",&n);
    28              for(int i=0;i<n;i++)
    29              {
    30                  cin>>s2;
    31                  if(s2.find(s1)!= s2.npos) cout<<s2<<endl;
    32              }
    33         }
    34         else{
    35             solve(s1);
    36             scanf("%d",&n);
    37              for(int i=0;i<n;i++)
    38              {
    39                  cin>>s2;
    40                   string s3=s2;
    41                  solve(s2);
    42 
    43                  if(s2.find(s1) != s2.npos) cout<<s3<<endl;
    44              }
    45         }
    46     }
    47     return 0;
    48 }
  • 相关阅读:
    邻接矩阵
    任务分配book
    10327
    二分+叉积判断方向 poj 2318 2398
    圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point
    2016年CCF第七次测试 俄罗斯方块
    trie树 Codeforces Round #367 D Vasiliy's Multiset
    十字链表 Codeforces Round #367 E Working routine
    树形DP CCPC网络赛 HDU5834 Magic boy Bi Luo with his excited tree
    (四面体)CCPC网络赛 HDU5839 Special Tetrahedron
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4367020.html
Copyright © 2020-2023  润新知