亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 4958 | 回復(fù): 13
打印 上一主題 下一主題

打印出字符串hello的所有子串 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2009-09-07 17:08 |只看該作者 |倒序?yàn)g覽
RT

游客,如果您要查看本帖隱藏內(nèi)容請(qǐng)回復(fù)


[ 本帖最后由 teebye 于 2009-9-7 17:12 編輯 ]

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2009-09-07 17:28 |只看該作者
看到你的代碼了,不過這個(gè)是python?怎么看著很別扭?

[ 本帖最后由 9命怪貓 于 2009-9-7 17:34 編輯 ]

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2009-09-08 01:38 |只看該作者
原帖由 teebye 于 2009-9-7 17:08 發(fā)表
RT

**** 本內(nèi)容被作者隱藏 *****

def all_sub_string( l ):
    if( len( l ) == 1 ):
        return [l]
    else:
        r = []
        for x in range( 1, len( l ) + 1 ):
            r.append( [ l[0] ] + l[ 1:x ] )
        a = all_sub_string( l[1:] )
        return  r + a


>>> all_sub_string(list('hello'));
[['h'], ['h', 'e'], ['h', 'e', 'l'], ['h', 'e', 'l', 'l'], ['h', 'e', 'l', 'l', 'o'], ['e'], ['e', 'l'], ['e', 'l', 'l'], ['e', 'l', 'l', 'o'], ['l'], ['l', 'l'], ['l', 'l', 'o'], ['l'], ['l', 'o'], ['o']]

[ 本帖最后由 orangetouch 于 2009-9-8 01:39 編輯 ]

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2009-09-08 09:20 |只看該作者
非遞歸的,ruby的寫法

| def print_sub_string(str)
      (0..str.size-1).each do|i|
       j = str.size-i
       until(j==0)
         puts str[i,j]
         j -=1
       end
     end
   end
  print_sub_string("hello")

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2009-09-08 09:21 |只看該作者
結(jié)果

hello
hell
hel
he
h
ello
ell
el
e
llo
ll
l
lo
l
o

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2009-09-08 10:24 |只看該作者

回復(fù) #1 teebye 的帖子

def sub(s):
    l = len(s)
    for i in range(0,l+1):
        for j in range(0,l+1):
            if i < j:
                print s[i:j]
sub("hello")

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2009-09-09 14:29 |只看該作者
本帖最后由 starfuck 于 2019-11-26 23:47 編輯












論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2009-09-09 22:31 |只看該作者
Except LZ's code ( so far I don't see it ), all the python code above have issue(s).
testing your function with this short string ('abc') shows all -- missing some sub-string.

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2009-09-09 23:15 |只看該作者
LZ's code is soooooo ugly ! is it python code ?

check your result with the following
ello
hllo
helo
hell
elo
ell
hlo
hll
llo
hel
heo
el
eo
lo
ll
ho
hl
he
h
e
l
o

[ 本帖最后由 mjus 于 2009-9-9 23:19 編輯 ]

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2009-09-09 23:26 |只看該作者
以我多年的看帖經(jīng)驗(yàn)。。lz一般貼的是RUBY。。。。
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP