Love丶FFC's Blog

CCF-CSP_20140903:字符串匹配

2019-12-13 10:00:31
阅读:813   •   评论:5
标签:,

问题描述

给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行。你的程序还需支持大小写敏感选项:当选项打开时,表示同一个字母的大写和小写看作不同的字符;当选项关闭时,表示同一个字母的大写和小写看作相同的字符。

输入格式

输入的第一行包含一个字符串S,由大小写英文字母组成。
  第二行包含一个数字,表示大小写敏感的选项,当数字为0时表示大小写不敏感,当数字为1时表示大小写敏感。
  第三行包含一个整数n,表示给出的文字的行数。
  接下来n行,每行包含一个字符串,字符串由大小写英文字母组成,不含空格和其他字符。

输出格式

输出多行,每行包含一个字符串,按出现的顺序依次给出那些包含了字符串S的行。

样例输入

Hello
1
5
HelloWorld
HiHiHelloHiHi
GrepIsAGreatTool
HELLO
HELLOisNOTHello

样例输出

HelloWorld
HiHiHelloHiHi
HELLOisNOTHello

样例说明

在上面的样例中,第四个字符串虽然也是Hello,但是大小写不正确。如果将输入的第二行改为0,则第四个字符串应该输出。

评测用例规模与约定

1<=n<=100,每个字符串的长度不超过100。

编程语言:Python

解题思想:

1.使用Python中的lower()方法和in关键字即可

2.对大小写是否敏感的情况分别进行处理

3.注意转为小写的时候不要使用赋值,否则最终输出的字符串是错误的

时间复杂度:O(n)

IDE代码如下:

  1. Sourcestr = input() # 输入寻找的字符串
  2. CaseSense = int(input()) # 输入大小写是否敏感,0为不敏感,1为敏感
  3. NOS = int(input()) # 输入匹配的字符串的个数
  4. for i in range(NOS):
  5. Targetstr = input() # 输入匹配的字符串
  6. if CaseSense == 0: # 大小写不敏感
  7. if Sourcestr.lower() in Targetstr.lower(): # 都使用小写来比较
  8. print(Targetstr)
  9. else: # 大小写敏感
  10. if Sourcestr in Targetstr:
  11. print(Targetstr)
  12.  

评论板

共有 5 条评论

  1. cheap real jordans

    Read reviews and was a little hesitant since I had already inputted my order. or possibly a but thank god, I had no issues. love the received item in a timely matter, they are in new condition. you ultimately choose so happy I made the purchase. Will be definitely be purchasing again.
    cheap real jordans https://www.cheapsneakeronline.com/

  2. cheap jordans for sale

    Read reviews and was a little hesitant since I had already inputted my order. or even but thank god, I had no issues. like the received item in a timely matter, they are in new condition. an invaluable so happy I made the purchase. Will be definitely be purchasing again.
    cheap jordans for sale https://www.realjordansretro.com/

  3. Gealpaste

    levitra generique arnaque Toxicities, which occurred in 22 of patients, included lethargy, peripheral edema, and hot flashes

  4. intuido

    can i buy cialis without a prescription Lenograstim Lenograstim is a substance that stimulates the production of a type of white blood cell from the bone marrow, known as neutrophils

  5. fqTkTxv

    buy cialis on line Crump M, Goss PE, Prince M, Girouard C

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:503361