bobobo1127 2016-09-23 00:29 采纳率: 0%
浏览 978

Python 问题--希望各位高手前来解答

Suppose you are given two strings named s1 and s2 (containing only lowercase letters). The string s1 is called
a “good” string if it contains s2, i.e., s2 is a substring of s1. For example, if s1 is smart and s2 is art, then
s1 is a good string because smart contains art. The string s1 is called “almost good” if it is not a “good”
string but inserting one character into it would make it a “good” string. For example, if s1 is smart and s2
is mark, then s1 is not a good string because mark is not a substring of smart. But s1 is an “almost good”
string because inserting the letter k in s1 (between r and t) makes it smarkt which is a “good” string because
it contains mark. The string s1 is called a “bad” string if it is neither a “good” nor an ”almost good” string.
You need to write two functions called isGood(s1, s2) and isAlmostGood(s1, s2) that return true if
and only if s1 is “good” and “almost good”, respectively.
Your program must ask the user to enter two input strings: first input string will be s1 and the second input
string will be s2. Both strings must be converted to lowercase letters. Then, the program must call the two
functions to determine whether s1 is a “good”, “almost good” or “bad” string. The result must be printed

  • 写回答

3条回答

  • 朕就是这么帅 2016-09-23 01:19
    关注

    你这属于伸手要代码的吧..你读下题目就知道该怎么做了啊,一到算法题,想到于求两个字符串集合的关系, 子集===>good, 有交集===>almost good, 无交集 ===>bad

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题