A11206 | Hex Dyslexia
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Copying large hexadecimal (base 16) strings by hand can be error prone, but that doesn't stop people from doing it. You've discovered a bug in the code that was likely caused by someone making a mistake when copying such a string. You suspect that whoever copied the string did not change any of the digits in the string, nor the length of the string, but may have permuted the digits arbitrarily. For example, if the original string was $0abc$ they may have changed it to $a0cb$ or $0bca$ , but not $abc$ or $0abb$ .
Unfortunately you don't have access to the original string nor the copied string, but you do know the length of the strings and their numerical absolute difference. You will be given this difference as a hexadecimal string $S$ , which has been zero-extended to be equal in length to the original and copied strings. Determine the smallest possible numerical value of the original string.
Unfortunately you don't have access to the original string nor the copied string, but you do know the length of the strings and their numerical absolute difference. You will be given this difference as a hexadecimal string $S$ , which has been zero-extended to be equal in length to the original and copied strings. Determine the smallest possible numerical value of the original string.
输入格式
Input will contain a hexadecimal string $S$ consisting only of digits $0$ to $9$ and lowercase English letters from $a$ to $f$ , with length at most $14$ . At least one of the characters is non-zero.
输出格式
If it is not possible, print "NO" (without quotes).
Otherwise, print the lowercase hexadecimal string corresponding to the smallest possible numerical value, including any necessary leading zeros for the length to be correct.
Otherwise, print the lowercase hexadecimal string corresponding to the smallest possible numerical value, including any necessary leading zeros for the length to be correct.
输入输出样例
输入 #1
f1e
输出 #1
NO
输入 #2
0f1e
输出 #2
00f1
输入 #3
12d2c
输出 #3
00314
The numerical value of a hexadecimal string is computed by multiplying each digit by successive powers of $16$ , starting with the rightmost digit, which is multiplied by $16^{0}$ . Hexadecimal digits representing values greater than $9$ are represented by letters: $a=10,b=11,c=12,d=13,e=14,f=15$ .
For example, the numerical value of $0f1e$ is $0·16^{3}+15·16^{2}+1·16^{1}+14·16^{0}=3870$ , the numerical value of $00f1$ is $0·16^{3}+0·16^{2}+15·16^{1}+1·16^{0}=241$ , and the numerical value of $100f$ is $1·16^{3}+0·16^{2}+0·16^{1}+15·16^{0}=4111$ . Since $3870+241=4111$ and $00f1$ is a permutation of $100f$ , $00f1$ is a valid answer to the second test case.
For example, the numerical value of $0f1e$ is $0·16^{3}+15·16^{2}+1·16^{1}+14·16^{0}=3870$ , the numerical value of $00f1$ is $0·16^{3}+0·16^{2}+15·16^{1}+1·16^{0}=241$ , and the numerical value of $100f$ is $1·16^{3}+0·16^{2}+0·16^{1}+15·16^{0}=4111$ . Since $3870+241=4111$ and $00f1$ is a permutation of $100f$ , $00f1$ is a valid answer to the second test case.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted