Compared against declared_pairs · told 12 of 12 deliberately broken copies apart · 2220 ms
def kind_of(ch):
kind = 0
if ch == ' ':
kind = 1
if ch == '\n':
kind = 2
if ch == '%':
kind = 3
if ch == '&':
kind = 4
if ch == '=':
kind = 5
if ch == '+':
kind = 6
return kind
def plain(ch):
letters = 'ABCDEFGHIJKLMNOP' + 'QRSTUVWXYZ' + 'abcdefghijklmnop' + 'qrstuvwxyz' + '0123456789' + '-._~'
for u in letters:
if ch == u:
return 1
return 0
def encoded(ch):
chars = ' \n\r\t' + '!"#' + '%' + "&'()*+,/" + ':;' + '<' + '=' + '>' + '?@' + '[' + '\\' + ']' + '^`' + '{|}'
hexes = '200A0D09' + '212223' + '25' + '262728292A2B2C2F' + '3A3B' + '3C' + '3D' + '3E' + '3F40' + '5B' + '5C' + '5D' + '5E60' + '7B7C7D'
i = 0
n = len(chars)
while i < n:
if chars[i] == ch:
return '%' + hexes[i * 2:i * 2 + 2]
i = i + 1
return ''
def solve(s):
out = ''
for ch in s:
kind = kind_of(ch)
if kind == 1:
out = out + '%20'
else:
if kind == 2:
out = out + '%0A'
else:
if kind == 3:
out = out + '%25'
else:
if kind == 4:
out = out + '%26'
else:
if kind == 5:
out = out + '%3D'
else:
if kind == 6:
out = out + '%2B'
else:
if plain(ch) == 1:
out = out + ch
else:
got = encoded(ch)
if got == '':
out = out + ch
else:
out = out + got
return out
12 test cases ship with it; the first three:
| in | out |
|---|---|
xqink ivrw xqink uslpki 0 | xqink%20ivrw%0Axqink%20%20uslpki%200 |
zjl jbnwi zjl levrq 1 | zjl%20jbnwi%0Azjl%20%20levrq%201 |
oncunt wxnb oncunt udahwb 2 | oncunt%20wxnb%0Aoncunt%20%20udahwb%202 |
GET https://research.zaiba.cloud/api/v1/programs/percent_encode
POST https://research.zaiba.cloud/api/v1/programs/percent_encode/run
{"input": "…"}
# 200 · X-DeAI-Rail: grant (free within the allowance) · output + signed receipt
GET https://research.zaiba.cloud/api/v1/programs/percent_encode/code
# 200 · text/plain · the tool as one Python file, written by the library's authors