A1162 | [COCI-2008_2009-contest4]#2 MJEHURIC
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Goran has five wooden pieces arranged in a sequence. There is a number between 1 and 5 inscribed on every piece, so that every number appears on exactly one of the five pieces.
Goran wants to order the pieces to form the sequence 1, 2, 3, 4, 5 and does it like this:
1. If the number on the first piece is greater than the number on the second piece, swap them.
2. If the number on the second piece is greater than the number on the third piece, swap them.
3. If the number on the third piece is greater than the number on the fourth piece, swap them.
4. If the number on the fourth piece is greater than the number on the fifth piece, swap them.
5. If the pieces don't form the sequence 1, 2, 3, 4, 5, go to step
1.
Write a program that, given the initial ordering of the pieces, outputs the ordering after each swap.
Goran wants to order the pieces to form the sequence 1, 2, 3, 4, 5 and does it like this:
1. If the number on the first piece is greater than the number on the second piece, swap them.
2. If the number on the second piece is greater than the number on the third piece, swap them.
3. If the number on the third piece is greater than the number on the fourth piece, swap them.
4. If the number on the fourth piece is greater than the number on the fifth piece, swap them.
5. If the pieces don't form the sequence 1, 2, 3, 4, 5, go to step
1.
Write a program that, given the initial ordering of the pieces, outputs the ordering after each swap.
输入格式
The first line contains five integers separated by single spaces, the ordering of the pieces.
The numbers will be between 1 and 5 (inclusive) and there will be no duplicates.
The initial ordering will not be 1, 2, 3, 4,
5.
The numbers will be between 1 and 5 (inclusive) and there will be no duplicates.
The initial ordering will not be 1, 2, 3, 4,
5.
输出格式
After any two pieces are swapped, output the ordering of the pieces, on a single line separated by spaces.
输入输出样例
输入 #1
2 1 5 3 4
输出 #1
1 2 5 3 4 1 2 3 5 4 1 2 3 4 5
输入 #2
2 3 4 5 1
输出 #2
2 3 4 1 5 2 3 1 4 5 2 1 3 4 5 1 2 3 4 5
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted