A14932 | Madoka and Math Dad
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Madoka finally found the administrator password for her computer. Her father is a well-known popularizer of mathematics, so the password is the answer to the following problem.
Find the maximum decimal number without zeroes and with no equal digits in a row, such that the sum of its digits is $n$ .
Madoka is too tired of math to solve it herself, so help her to solve this problem!
Find the maximum decimal number without zeroes and with no equal digits in a row, such that the sum of its digits is $n$ .
Madoka is too tired of math to solve it herself, so help her to solve this problem!
输入格式
Each test contains multiple test cases. The first line contains a single integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases. Description of the test cases follows.
The only line of each test case contains an integer $n$ ( $1 \le n \le 1000$ ) — the required sum of the digits.
The only line of each test case contains an integer $n$ ( $1 \le n \le 1000$ ) — the required sum of the digits.
输出格式
For each test case print the maximum number you can obtain.
输入输出样例
输入 #1
5 1 2 3 4 5
输出 #1
1 2 21 121 212
The only numbers with the sum of digits equal to $2$ without zeros are $2$ and $11$ . But the last one has two ones in a row, so it's not valid. That's why the answer is $2$ .
The only numbers with the sum of digits equal to $3$ without zeros are $111$ , $12$ , $21$ , and $3$ . The first one has $2$ ones in a row, so it's not valid. So the maximum valid number is $21$ .
The only numbers with the sum of digits equals to $4$ without zeros are $1111$ , $211$ , $121$ , $112$ , $13$ , $31$ , $22$ , and $4$ . Numbers $1111$ , $211$ , $112$ , $22$ aren't valid, because they have some identical digits in a row. So the maximum valid number is $121$ .
The only numbers with the sum of digits equal to $3$ without zeros are $111$ , $12$ , $21$ , and $3$ . The first one has $2$ ones in a row, so it's not valid. So the maximum valid number is $21$ .
The only numbers with the sum of digits equals to $4$ without zeros are $1111$ , $211$ , $121$ , $112$ , $13$ , $31$ , $22$ , and $4$ . Numbers $1111$ , $211$ , $112$ , $22$ aren't valid, because they have some identical digits in a row. So the maximum valid number is $121$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted