次世代言語議論スレ[Go Rust Kotlin Scala]第4世代at TECH
次世代言語議論スレ[Go Rust Kotlin Scala]第4世代 - 暇つぶし2ch355:デフォルトの名無しさん
17/05/11 17:14:36.14 +i4P6kRh.net
はいはい・・・。
んじゃ、検索で見つけた位置も追加で表示するように拡張。
import System.Environment
search w = search' (False,0,[],(1,0)) w
where
search' (b,n,ps,_) _ [] = (b,n,reverse ps)
search' (b,n,ps,(y,_)) w (c:cs) | c == '\n' = search' (b,n,ps,(y + 1,0)) w cs
search' (_,n,ps,(y,x)) w (c:cs) | take (length w) (c:cs) == w = search' (True,n + 1,(y,x + 1):ps,(y,x + 1)) w cs
search' (b,n,ps,(y,x)) w (_:cs) = search' (b,n,ps,(y, x + 1)) w cs
search2 w = search' (False,0,[],(1,0)) w
where
search' (b,n,ps,_) _ [] = (b,n,reverse ps)
search' (b,n,ps,(y,_)) w (c:cs) | c == '\n' = search' (b,n,ps,(y + 1,0)) w cs
search' (_,n,ps,(y, x)) w cts | take (length w) cts == w = search' (True,n + 1,(y, x + 1):ps,(y, x + 1)) w $ drop (length w) cts
search' (b,n,ps,(y,x)) w (_:cs) = search' (b,n,ps,(y, x + 1)) w cs
-- main = do 7777
-- (file:word:_) <- getArgs
-- content <- readFile file
-- print $ search word content
main = getArgs >>= \(file:word:_) -> readFile file >>= print.search2 word


次ページ
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch