题目链接

Capitalize the Names

题目说明

把引号中的姓名改成首字母大写的格式,文件名中的内容不变。

开始文件

The first name is "JOHN DOE" and its file is "JOHN_DOE.file"
The second name is "JANE DOE" and its file is "JANE_DOE.file"
The third name is "JAMES TIBERIUS KIRK" and its file is "JAMES_TIBERIUS_KIRK.file"
The fourth name is "SPOCK" and its file is "SPOCK.file"
The fifth name is "JEAN-LUC PICARD" and its file is "JEAN_LUC_PICARD.file"
The sixth name is "EUGENE WESLEY RODDENBERRY" and its file is "EUGENE_WESLEY_RODDENBERRY.file"
The seventh name is "WILLIAM NELSON JOY" and its file is "WILLIAM_NELSON_JOY.file"
The last name is "BRAM MOOLENAAR" ind its file is "BRAM_MOOLENAAR.file"

结束文件

The first name is "John Doe" and its file is "JOHN_DOE.file"
The second name is "Jane Doe" and its file is "JANE_DOE.file"
The third name is "James Tiberius Kirk" and its file is "JAMES_TIBERIUS_KIRK.file"
The fourth name is "Spock" and its file is "SPOCK.file"
The fifth name is "Jean-Luc Picard" and its file is "JEAN_LUC_PICARD.file"
The sixth name is "Eugene Wesley Roddenberry" and its file is "EUGENE_WESLEY_RODDENBERRY.file"
The seventh name is "William Nelson Joy" and its file is "WILLIAM_NELSON_JOY.file"
The last name is "Bram Moolenaar" ind its file is "BRAM_MOOLENAAR.file"

最佳分数

21

我的分数

27

qqf"wlguwwl.wl.<CR>q7@q5Gfl~ZZ

第一次尝试

感觉有点麻烦,尤其是第 5 行有个例外。

qq0f"wlguwwl.wl.jq7@q5Gfl~ZZ

28 分,差 7 分。

第二次尝试

稍微优化一下。

qqf"wlguwwl.wl.<CR>q7@q5Gfl~ZZ

27 分,差 6 分。

第三次尝试

看来得把 5 行的例外处理好。替换试试。

:%s/\u\zs\u*\ze[- "]/\L&/g<CR>ZZ

29 分,还多了。

第四次尝试

直接看吧。

@rocker_zzy

qqf"llguwEbl.wl.wl.<CR>q7@qZZ

26 分。重点是 Ebl,这个专门处理第 5 行的例外。那可以再简化成 Eh,改造下。

qqf"wlguwEh.wl.wl.<CR>q7@qZZ

25 分,还差 4 分。

第五次尝试

想不出来还能怎么优化了。

@jkrause314

qqvi"uvUf"b.b.+q7@qZZ

21 分。这思路果然不同凡响,先全转换成小写,然后从后往前依次把第一个字母转换成大写,巧妙处理了第 5 行的例外。

最佳操作

@jkrause314

qqvi"uvUf"b.b.+q7@qZZ

实用操作

@jkrause314

qqvi"uvUf"b.b.+q7@qZZ

21 分。

大小写转换教科书般的操作。

文章目录