Throwing cards away I
来源:互联网 发布:南京证券开户软件 编辑:程序博客网 时间:2024/05/29 03:17
Given is an ordered deck of n cards numbered 1
to n with card 1 at the top and card n at the
bottom. The following operation is performed as
long as there are at least two cards in the deck:
Throw away the top card and move
the card that is now on the top of the
deck to the bottom of the deck.
Your task is to find the sequence of discarded
cards and the last, remaining card.
Input
Each line of input (except the last) contains a
number n ≤ 50. The last line contains ‘0’ and
this line should not be processed.
Output
For each number from the input produce two
lines of output. The first line presents the sequence
of discarded cards, the second line reports
the last remaining card. No line will have
leading or trailing spaces. See the sample for the
expected format.
Sample Input
7
19
10
6
0
Sample Output
Discarded cards: 1, 3, 5, 7, 4, 2
Remaining card: 6
Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 4, 8, 12, 16, 2, 10, 18, 14
Remaining card: 6
Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8
Remaining card: 4
Discarded cards: 1, 3, 5, 2, 6
to n with card 1 at the top and card n at the
bottom. The following operation is performed as
long as there are at least two cards in the deck:
Throw away the top card and move
the card that is now on the top of the
deck to the bottom of the deck.
Your task is to find the sequence of discarded
cards and the last, remaining card.
Input
Each line of input (except the last) contains a
number n ≤ 50. The last line contains ‘0’ and
this line should not be processed.
Output
For each number from the input produce two
lines of output. The first line presents the sequence
of discarded cards, the second line reports
the last remaining card. No line will have
leading or trailing spaces. See the sample for the
expected format.
Sample Input
7
19
10
6
0
Sample Output
Discarded cards: 1, 3, 5, 7, 4, 2
Remaining card: 6
Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 4, 8, 12, 16, 2, 10, 18, 14
Remaining card: 6
Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8
Remaining card: 4
Discarded cards: 1, 3, 5, 2, 6
Remaining card: 4
#include <iostream>#include<cstdio>using namespace std;int a[100];int main(){ int n,t,h,i; while(cin>>n) { if(n==0)break; for(i=1;i<=n+1;i++) a[i]=i;h=1;t=n+1; cout<<"Discarded cards:"; while(h<t-1) { if(h<t-2) cout<<" "<<a[h]<<","; else cout<<" "<<a[h]; h++; a[t]=a[h]; t++; h++; } cout<<endl; cout<<"Remaining card:"; cout<<" "<<a[h]; cout<<endl; }}
阅读全文
0 0
- Throwing cards away I
- Throwing cards away I
- uva:Throwing cards away I
- UVa10935 - Throwing cards away I
- UVA10935 - Throwing cards away I
- uva10935 - Throwing cards away I
- 10935 - Throwing cards away I
- UVa10935 - Throwing cards away I
- Throwing cards away I uva1594
- UVA_10935: Throwing cards away I
- Throwing cards away I--队列
- Throwing cards away I UVA
- UVA-Throwing cards away I
- Throwing cards away I UVA
- UVA 10935 - Throwing cards away I
- UVA 10935 - Throwing cards away I
- UVa 10935 - Throwing cards away I STL
- uva 10935 - Throwing cards away I
- Ubuntu14.04下安装ros indigo opencv2.4.11
- JS学习(10)----DOM
- 南阳理工oj-水池数目
- PAT(Basic Level)_1013_数素数
- 程序员面试金典:机器人走方格II、魔术索引I
- Throwing cards away I
- 蓝牙加密三【Definition of Keys】
- 运算符
- 2036: 聪明的阿卑多
- HDU 1465 不容易系列之一
- poj1896—Cable TV Network(点联通度的求解)
- N的N次方
- NYOJ 477 A+B Problem III
- markdown简明语法