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

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 7672 | 回復: 9
打印 上一主題 下一主題

[練習] 尋找單詞 [復制鏈接]

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術圖書徽章
日期:2014-03-05 01:33:12技術圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2014-03-29 23:38 |只看該作者 |倒序瀏覽

給定一個輸入的字符串和
一個包含各種單詞的字典,
用空格將字符串分割成一系列字典中存在的單詞。

example: 字典

WORDS = %w[
100 200 ARG Linux Note To UNIX a an and apple as
available between command commend contains delimited
dict dictionary each elect file generate input is
like line list newline numbers of on operating options
permutations random select sentence sentences sep
separate share shuf shuffle standard system the
treat usr with words
]

字符串:
sentenceselect
Toshufflethenumbersbetween100and200

那么我們應該得到:
["sentence", "select"] ["sentences", "elect"]
["To", "shuffle", "the", "numbers", "between", "100", "and", "200"]

論壇徽章:
31
CU大;照
日期:2013-03-13 15:15:08CU大;照
日期:2013-05-20 10:46:18CU大;照
日期:2013-05-20 10:46:25CU大;照
日期:2013-05-20 10:46:31CU大;照
日期:2013-05-20 10:46:38CU大;照
日期:2013-05-20 10:46:44CU大;照
日期:2013-09-18 15:16:55CU大;照
日期:2013-09-18 15:18:22CU大;照
日期:2013-09-18 15:18:43CU十二周年紀念徽章
日期:2013-10-24 15:41:34丑牛
日期:2013-12-01 10:11:07水瓶座
日期:2014-01-15 08:47:25
2 [報告]
發(fā)表于 2014-03-30 22:10 |只看該作者
這種單詞分割很不好處理啊。

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術圖書徽章
日期:2014-03-05 01:33:12技術圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
3 [報告]
發(fā)表于 2014-03-30 23:48 |只看該作者
回復 2# ddd010


    是!

論壇徽章:
13
雙魚座
日期:2013-10-23 09:30:05數(shù)據庫技術版塊每日發(fā)帖之星
日期:2016-04-20 06:20:00程序設計版塊每日發(fā)帖之星
日期:2016-03-09 06:20:002015亞冠之塔什干火車頭
日期:2015-11-02 10:07:452015亞冠之德黑蘭石油
日期:2015-08-30 10:07:07數(shù)據庫技術版塊每日發(fā)帖之星
日期:2015-08-28 06:20:00數(shù)據庫技術版塊每日發(fā)帖之星
日期:2015-08-05 06:20:002015年迎新春徽章
日期:2015-03-04 09:57:09辰龍
日期:2014-12-03 14:45:52酉雞
日期:2014-07-23 09:46:23亥豬
日期:2014-03-13 08:46:22金牛座
日期:2014-02-11 09:36:21
4 [報告]
發(fā)表于 2014-03-31 10:48 |只看該作者
#!/usr/bin/env ruby

WORDS = %w[
100 200 ARG Linux Note To UNIX a an and apple as
available between command commend contains delimited
dict dictionary each elect file generate input is
like line list newline numbers of on operating options
permutations random select sentence sentences sep
separate share shuf shuffle standard system the
treat usr with words
]

start = 0
str='sentenceselect'
str='Toshufflethenumbersbetween100and200'
length = str.length
w=[]
(start..length).each do |s|
        (s+1..length).each do |x|
           tmp_word=str[s...x]
           w.push(tmp_word) if WORDS.count(tmp_word) > 0
        end
end

puts w.inspect()

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術圖書徽章
日期:2014-03-05 01:33:12技術圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
5 [報告]
發(fā)表于 2014-04-01 00:05 |只看該作者
本帖最后由 rubyish 于 2014-04-01 00:15 編輯

回復 4# bikong0411

贊美   

but error!~

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術圖書徽章
日期:2014-03-05 01:33:12技術圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
6 [報告]
發(fā)表于 2014-04-01 04:22 |只看該作者
本帖最后由 rubyish 于 2014-04-24 19:02 編輯

dddddddddddd~

論壇徽章:
13
雙魚座
日期:2013-10-23 09:30:05數(shù)據庫技術版塊每日發(fā)帖之星
日期:2016-04-20 06:20:00程序設計版塊每日發(fā)帖之星
日期:2016-03-09 06:20:002015亞冠之塔什干火車頭
日期:2015-11-02 10:07:452015亞冠之德黑蘭石油
日期:2015-08-30 10:07:07數(shù)據庫技術版塊每日發(fā)帖之星
日期:2015-08-28 06:20:00數(shù)據庫技術版塊每日發(fā)帖之星
日期:2015-08-05 06:20:002015年迎新春徽章
日期:2015-03-04 09:57:09辰龍
日期:2014-12-03 14:45:52酉雞
日期:2014-07-23 09:46:23亥豬
日期:2014-03-13 08:46:22金牛座
日期:2014-02-11 09:36:21
7 [報告]
發(fā)表于 2014-04-01 08:55 |只看該作者
回復 5# rubyish


    沒明白你要干啥

論壇徽章:
13
雙魚座
日期:2013-10-23 09:30:05數(shù)據庫技術版塊每日發(fā)帖之星
日期:2016-04-20 06:20:00程序設計版塊每日發(fā)帖之星
日期:2016-03-09 06:20:002015亞冠之塔什干火車頭
日期:2015-11-02 10:07:452015亞冠之德黑蘭石油
日期:2015-08-30 10:07:07數(shù)據庫技術版塊每日發(fā)帖之星
日期:2015-08-28 06:20:00數(shù)據庫技術版塊每日發(fā)帖之星
日期:2015-08-05 06:20:002015年迎新春徽章
日期:2015-03-04 09:57:09辰龍
日期:2014-12-03 14:45:52酉雞
日期:2014-07-23 09:46:23亥豬
日期:2014-03-13 08:46:22金牛座
日期:2014-02-11 09:36:21
8 [報告]
發(fā)表于 2014-04-01 08:57 |只看該作者
回復 6# rubyish


    學習

論壇徽章:
0
9 [報告]
發(fā)表于 2014-06-07 22:17 |只看該作者
本帖最后由 gdw1986 于 2014-06-07 22:17 編輯

#!/usr/bin/env ruby
WORDS = %q[
100 200 ARG Linux Note To UNIX a an and apple as
available between command commend contains delimited
dict dictionary each elect file generate input is
like line list newline numbers of on operating options
permutations random select sentence sentences sep
separate share shuf shuffle standard system the
treat usr with words
]
Subwords=WORDS.split

spec=[]
string1="sentenceselect"
string2="Toshufflethenumbersbetween100and200"
Subwords.each do |words| if string1=~/#{words}/ or string2=~/#{words}/
       spec<< words if !spec.include?("#{words}")
end
end
puts spec

執(zhí)行結果:
100
200
To
a
an
and
between
elect
numbers
select
sentence
sentences
shuf
shuffle
the
稍微改動了點,初學者,不知道這個符不符合要求?

論壇徽章:
5
白羊座
日期:2014-10-28 11:23:27水瓶座
日期:2015-01-20 10:19:022015亞冠之柏斯波利斯
日期:2015-07-11 18:17:2015-16賽季CBA聯(lián)賽之同曦
日期:2015-12-23 12:38:582016猴年福章徽章
日期:2016-02-18 15:30:34
10 [報告]
發(fā)表于 2014-08-09 00:21 |只看該作者
  1. #!/usr/bin/env ruby
  2. WORDS = %w[
  3. 100 200 ARG Linux Note To UNIX a an and apple as
  4. available between command commend contains delimited
  5. dict dictionary each elect file generate input is
  6. like line list newline numbers of on operating options
  7. permutations random select sentence sentences sep
  8. separate share shuf shuffle standard system the
  9. treat usr with words
  10. ]

  11. string1="sentenceselect"
  12. string2="Toshufflethenumbersbetween100and200"
  13. class String
  14.     def ssss(words, rs=[])
  15.         words.each do |x|
  16.             if self =~ /^#{x}/
  17.                 rs =[x]+ self.sub(x,"").ssss(words,rs)
  18.             end
  19.         end
  20.         rs
  21.     end
  22. end
  23. p string1.ssss(WORDS)
  24. p string2.ssss(WORDS)
  25. ["sentences", "elect", "sentence", "select"]
  26. ["To", "shuffle", "the", "numbers", "between", "100", "and", "200", "an", "a", "shuf"]
復制代碼
寫的不好,沒有完全達到效果
您需要登錄后才可以回帖 登錄 | 注冊

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP