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 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算