A7975 | Harry Potter and the History of Magic
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.
So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.
Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than $2011$ , or strictly before than $1000$ . To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.
So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.
Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than $2011$ , or strictly before than $1000$ . To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.
输入格式
The first input line contains an integer $n$ ( $1<=n<=1000$ ). It represents the number of dates in Harry's notes. Next $n$ lines contain the actual dates $y_{1}$ , $y_{2}$ , ..., $y_{n}$ , each line contains a date. Each date is a four-digit integer ( $1000<=y_{i}<=9999$ ).
输出格式
Print $n$ numbers $z_{1}$ , $z_{2}$ , ..., $z_{n}$ ( $1000<=z_{i}<=2011$ ). They are Ron's resulting dates. Print each number on a single line. Numbers $z_{i}$ must form the non-decreasing sequence. Each number $z_{i}$ should differ from the corresponding date $y_{i}$ in no more than one digit. It is not allowed to change the first digit of a number into $0$ . If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).
输入输出样例
输入 #1
3 1875 1936 1721
输出 #1
1835 1836 1921
输入 #2
4 9999 2000 3000 3011
输出 #2
1999 2000 2000 2011
输入 #3
3 1999 5055 2000
输出 #3
No solution
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted