Re: [問題] 邏輯問題
※ 引述《tkcn (小安)》之銘言:
: ※ 引述《hangting ()》之銘言:
: : 我有個問題
: : 使用者輸入字串
: : 如果aaa則輸出0,如果遇到aba則輸出1
: : ex. aab aba aabaaa
: : result: 100
: : ex. aaa b abaaaabbababa
: : result: 0101
: : 效率與簡單為重,大大們會怎麼作呢?
: : 我想到的作法是,以兩個b以上為條件,把字串split,再去作條件測試
: 其實我認為直接用 indexOf 去檢查就足夠了
: 因為在做字串比對時,只要前方的字首不同時,
: 就不會繼續完成目前的檢查,而是從下一個字元開始
: 所以與其先過濾掉部份字串,還不如直接檢查就好
其實我覺得原PO的這個問題的定義不清。~.~
關於這種格式在處理上應該盡量利用正則表示式來處理會比較好,
http://blog.matrix.org.cn/blueRockey/date/200605
這網頁下方有一些關於字串用正則式的替換,
透過find() 跟 appendReplacement 的處理,
再配合 "(aaa)|(aba)" 的regexp推測應該可以處理,
不過公司的電腦沒有Java環境,所以就不實做了,只提出來做參考。:P
--
String temp="relax"; | Life just like programing
while(buringlife) String.forgot(temp); | to be right or wrong
while(sleeping) brain.setMemoryOut(); | need not to say
stack.push(life.running); | the complier will
stack.push(scouting.buck()); | answer your life
stack.push(bowling.practice()); | Bone everything
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.218.69.114
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 11 篇):