鱼C论坛

 找回密码
 立即注册
查看: 846|回复: 4

求解答。。 非常非常感激

[复制链接]
发表于 2019-1-8 08:11:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
2.
Write a function called findIt that is a refactor of the following code. Your function must not use recursion.
## Determine whether or not text is in string.
     #  @param text the text to search for
     #  @param string the string to search for text
     #  @return True if string is in text, False otherwise
     #
     def find(text, string) :
        if text.startswith(string) :
           return True
        elif len(string) < len(text) :
           return find(text[1 : ], string)
        return False

3. Write a function called countIt. This function is an ammended version of findIt. It returns the number of times a substring is present in a string. For example
countIt(‘abaaba’,‘ab’) should equal 2
countIt(‘abaaba’,‘baa’) should equal 1
countIt(‘abaaba’,‘c’) should equal 0

4. Write a function called countRec. This is a refactored version of countIt. Your function must use recursion.
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-1-8 08:56:29 | 显示全部楼层
都是一些基础的操作,你把你的代码贴上来先
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-1-8 20:18:47 | 显示全部楼层
BngThea 发表于 2019-1-8 08:56
都是一些基础的操作,你把你的代码贴上来先

就是不会才问的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-1-8 21:10:38 | 显示全部楼层
编写一个名为findIt的函数,它是以下代码的重构。您的函数不能使用递归。
##确定文本是否在字符串中。
     #@参数文本搜索的文本
     #@参数字符串要搜索的字符串文本
     #@返回真,如果字符串文本,否则返回False
     #
     高清找到(文字,字符串):
        如果text.startswith(串):
           返回True
        elif len(string)<len(text):
           return find(text [1:],string)
        返回False

3.编写一个名为countIt的函数。此函数是findIt的修订版本。它返回字符串中存在子字符串的次数。例如
countIt('abaaba','ab')应该等于2
countIt('abaaba','baa')应该等于1
countIt('abaaba','c')应该等于0

4.编写一个名为countRec的函数。这是countIt的重构版本。您的函数必须使用递归。


写代码自己写?不要一上来求代码?自己多做
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-3-30 11:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表