| acmsguru |
|---|
| Finished |
4:spam" represents the string "spam", "
0:" represents an empty string.
i1024e" represents the number 1024.
<itemn-1>e". Each item of the list itemi is a supported data structure encoded using bencoding technique. Lists are allowed to be empty.li101el4:spami1024eee" represents the list "[ 101, [ "spam", 1024 ] ]".
<keyn-1><valuen-1>e". All keys and values are supported data structures encoded using bencoding technique. A dictionary may have duplicate keys and/or values. Dictionaries are allowed to be empty.d1:a0:1:pl1:b2:cdee" represents the dictionary with string key "a" mapped into an empty string "", and key "p" mapped into the list "[ "b", "cd" ]".
if the following two conditions are met: 2:bc" is not considered a valid bencoded object even though it represents a correctly encoded string "bc".
. If c is not a
, it also has to find the longest prefix of c which could be a prefix of some
. Formally, you should find a maximal position j within the given character sequence c, such that a prefix of c up to, but not including, character at position j could be a prefix of some
. If the given character sequence c is not a
, but the entire sequence c is a prefix of some
, then j is considered equal to the length of c.ok" (without quotes) if the given input character sequence is a valid bencoded object. Otherwise, print message "
Error at position j!". The first character of the input sequence is considered to have position "
0".
sample input | sample output |
14 li10e11:abcdefghijke | Error at position 6! |
sample input | sample output |
10 i-1e | Error at position 1! |
sample input | sample output |
3 i2 | Error at position 2! |
sample input | sample output |
18 dli1eei1ei1eli1eee | ok |
li10e1" can be extended to a valid bencoded object while not exceeding 14 characters in length (for example, "
li10e1:xe"). It's not the case with longer prefixes of length 7 and more, so j=6 in this case.
| Name |
|---|


