zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    用phpStudy来安装织梦cms,dedecms的本地测试
    如何不给花一分钱,关键词怎么霸屏百度首页?
    关键词挖掘工具_关键词拓展工具集合
    如何用iframe在网页中插入另一个网页的一部分内容,做成页中页
    mysql数据库中如何修改已建好的表中的【列名】【列的属性】
    为了让你的网页能在更多的服务器上正常地显示,还是加上“SET NAMES UTF8”吧
    php 构造函数格式,具体该怎么写?应该注意什么呢?
    win7(64位)php5.5-Apache2.4-mysql5.6环境安装
    JS滑动
    Codeforces Round #450 (Div. 2) C. Remove Extra One 题解
  • 原文地址:https://www.cnblogs.com/shawn-ji/p/4652541.html
Copyright © 2011-2022 走看看