LL Golf Hole 2 - 文字列に含まれる単語の最初の文字を大文字にする
Posted feedbacks - OCaml
標準ライブラリ内でがんばる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | (fun s->String.iter(fun c->try let rec l p=s.[p]<-Char.uppercase s.[p];
l(String.index_from s p c+1)in l 0with _->())" \t\n\r\012\011";s)
"LL day and night";;
(fun s->for i=0to 5do try let rec l p=s.[p]<-Char.uppercase s.[p];
l(String.index_from s p" \t\n\r\012\011".[i]+1)in l 0with _->()done;s)
"LL future";;
#load "str.cma";;
open Str;;
global_substitute(regexp"[A-Za-z0-9][A-Za-z0-9]*")
(fun s->String.capitalize(matched_string s))
"LL day and night";;
#load "str.cma";;
(fun s->String.concat" "(List.map String.capitalize
(Str.split (Str.regexp"[ \t\n\r\012\011]")s)))
"LL future";;
|


takano32
#6901()
[
Ruby
]
Rating2/10=0.20
文字列に含まれる単語について、それぞれの単語の最初の文字を大文字にしてください。
たとえば、"LL future" と与えられたときは "LL Future" と出力する。"LL day and night" と与えられたときは "LL Day And Night" と出力する。
与えられる文字列はリテラルで表記する、標準入力で与えられる、引数で与えられるなどは自由とします。
余力のあるものはこのプログラムを短くしてみたり、短くしてみたり、短くしてください。
※LL Future実行委員の高野光弘です。この出題は LL Future公式の出題であり、優れたものについてはLL Golfのセッションでご紹介させていただくかもしれません。ご理解の上、ご投稿ください。また、LL Futureのチケットは現在も発売中です。よろしければ、メインイベントの方にもぜひご参加ください。
see: LL Golf
Rating2/10=0.20-0+
[ reply ]