Compared against declared_pairs · told 12 of 12 deliberately broken copies apart · 1935 ms
def solve(s):
pairs = []
i = 0
n = len(s)
while i < n:
if s[i] == '"':
i = i + len('"')
key = ''
while i < n and s[i] != '"':
key = key + s[i]
i = i + len(s[i])
i = i + len('"')
while i < n and s[i] not in '0123456789':
i = i + len(s[i])
num = ''
while i < n and s[i] in '0123456789':
num = num + s[i]
i = i + len(s[i])
pairs = pairs + [key + '\n' + num]
else:
i = i + len(s[i])
pairs = sorted(pairs)
res = '{'
j = 0
while j < len(pairs):
if j > 0:
res = res + ','
item = pairs[j]
k = ''
v = ''
seen = False
for ch in item:
if ch == '\n' and seen == False:
seen = True
elif seen:
v = v + ch
else:
k = k + ch
res = res + '"' + k + '":' + v
j = j + len('x')
return res + '}'
12 test cases ship with it; the first three:
| in | out |
|---|---|
{"b":7,"a":11} | {"a":11,"b":7} |
{"b":9,"a":20} | {"a":20,"b":9} |
{"b":5,"a":16} | {"a":16,"b":5} |
GET https://research.zaiba.cloud/api/v1/programs/json_sorted_keys_minified
POST https://research.zaiba.cloud/api/v1/programs/json_sorted_keys_minified/run
{"input": "…"}
# 200 · X-DeAI-Rail: grant (free within the allowance) · output + signed receipt
GET https://research.zaiba.cloud/api/v1/programs/json_sorted_keys_minified/code
# 200 · text/plain · the tool as one Python file, written by the library's authors