Compared against declared_pairs · told 10 of 10 deliberately broken copies apart · 1166 ms
up = {'a':'A','b':'B','c':'C','d':'D','e':'E','f':'F','g':'G','h':'H','i':'I','j':'J','k':'K','l':'L','m':'M','n':'N','o':'O','p':'P','q':'Q','r':'R','s':'S','t':'T','u':'U','v':'V','w':'W','x':'X','y':'Y','z':'Z'}
lo = {'A':'a','B':'b','C':'c','D':'d','E':'e','F':'f','G':'g','H':'h','I':'i','J':'j','K':'k','L':'l','M':'m','N':'n','O':'o','P':'p','Q':'q','R':'r','S':'s','T':'t','U':'u','V':'v','W':'w','X':'x','Y':'y','Z':'z'}
def lines(s):
out = []
cur = ''
for ch in s:
if ch == '\n':
out = out + [cur]
cur = ''
else:
cur = cur + ch
if cur != '':
out = out + [cur]
return out
def joinl(xs):
out = ''
for i, x in enumerate(xs):
out = out + ('\n' if i > 0 else '') + x
return out
def strip1(l):
while l != '' and l[0] in ' \t':
l = l[1:]
while l != '' and l[-1] in ' \t':
l = l[:-1]
return l
def solve(s):
lines_list = lines(s)
out_lines = []
for line in lines_list:
line = strip1(line)
if line == '':
out_lines = out_lines + [line]
continue
first = line[0]
rest = line[1:]
first_up = up[first] if first in up else first
rest_lo = ''
for ch in rest:
rest_lo = rest_lo + (lo[ch] if ch in lo else ch)
out_lines = out_lines + [first_up + rest_lo]
return joinl(out_lines)
12 test cases ship with it; the first three:
| in | out |
|---|---|
ailjq zkd qhn 0 | Ailjq Zkd Qhn 0 |
sjkenm pxeyz fgakby 1 | Sjkenm Pxeyz Fgakby 1 |
mkm nqd tnawo 2 | Mkm Nqd Tnawo 2 |
GET https://research.zaiba.cloud/api/v1/programs/lines_title_case
POST https://research.zaiba.cloud/api/v1/programs/lines_title_case/run
{"input": "…"}
# 200 · X-DeAI-Rail: grant (free within the allowance) · output + signed receipt
GET https://research.zaiba.cloud/api/v1/programs/lines_title_case/code
# 200 · text/plain · the tool as one Python file, written by the library's authors