• UVa 1647


    这个题目。。。。

    想上题意

    10935 Throwing cards away I

    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

    Remaining card: 4

    我的分(吐)析(槽):

    这个题目,看题意就知道非常适合用STL中的deque容器,因为要频繁地头尾两端操作嘛

    明显水题,,,但是我还是被搞的要死,因为格式,,因为格式,,因为格式   要说三遍

    最后的输出 要仔细地看  Discarded cards: 1, 3, 5, 2, 6 

    冒号后有空格,数字前面有空格,数字后面有逗号,逗号后面没空格。。。想把题目过了就必须要仔细仔细得注意这些啊。。。

    我的代码

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<deque>
     4 #include<vector>
     5 using namespace std;
     6 
     7 deque<int> cards;
     8 vector<int> dis;
     9 int main()
    10 {
    11     vector<int>::iterator it;
    12     void change(deque<int> & c);
    13     int n;
    14     while (cin >> n&&n != 0){
    15         dis.clear();
    16         cards.clear();
    17         for (int i = 0; i < n; i++){
    18             cards.push_back(i+1);
    19         }       //容器填充   序列生成
    20         for (int i = 0; i < n-1;i++)
    21             change(cards);
    22         cout << "Discarded cards: ";
    23         for (it = dis.begin(); it != dis.end(); it++){
    24             cout << *it;
    25             if (it != dis.end() - 1)     cout << ', ';
    26         }
    27         cout << endl;
    28         cout <<"Remaining card: " <<cards.front()<<endl;
    29     }
    30     return 0;
    31 
    32 
    33 }
    34 
    35 void change(deque<int> & c)
    36 {
    37     dis.push_back(c.front());
    38     c.pop_front();
    39     int temp = c.front();
    40     c.pop_front();
    41     c.push_back(temp);
    42 }
    View Code
  • 相关阅读:
    Office EXCEL 如何设置最大行高
    网站SEO优化的方法
    ajax序列化表单,再也不用通过data去一个个的传值了
    java实现网站paypal支付功能并且异步修改订单的状态
    jquery报.live() is not a function的解决方法
    如何判断服务器是否挂掉
    mysql实现分页的几种方式
    sqlserver实现分页的几种方式
    十年前,女:“对不起,我不会喜欢你的,你不要再坚持了,就好比让 Linux 和 Windows 同时运行在一台PC机上,可能吗?
    实际项目开发中为什么引用的外部样式没有什么效果
  • 原文地址:https://www.cnblogs.com/shawn-ji/p/4652541.html
Copyright © 2020-2023  润新知