10935 - Throwing cards away I

10935 - Throwing cards away I_第1张图片

紫书上习题5-3;会用vector这题就是大水题(其他方法没试),但我做好之后,格式就一直错,一直找不出,那就先放着吧;

我的:

#include 
#include 
using namespace std;
#include 
int main()
{
    int n;
    vectors;
    vectora;
    while(cin>>n&&n<=50&&n!=0){
        while(!s.empty()){
            s.pop_back();
        }
        while(!a.empty()){
            a.pop_back();
        }
        for(int i=1;i<=n;i++){
            s.push_back(i);
        }
       while(s.size()>=2){
            a.push_back(s.front());
            s.erase(s.begin());
            s.push_back(s.front());
            s.erase(s.begin());
        }
        cout<<"Discarded cards: ";
        while(!a.empty()){
            if(a.size()!=1){
               cout<

别人的:

#include"iostream"
#include"algorithm"
#include"vector"
#include"map"
#include"string"
#include"deque"
#include"queue"
#include"stack"
#include"cstdio"
#include"cmath"
using namespace std;
int main()
{
    //freopen("a.txt","r",stdin);
    int n;
    while(cin>>n&&n)
    {
        cout<<"Discarded cards:";
        dequea;
        int i;
        for(i=1;i<=n;i++)
            a.push_back (i);          //23456
        while(a.size()!=1)
        {
            int t=a.front();
            if(a.size()>2)
                cout<<" "<

基本上差不多,就是格式不一样,也找不出;

你可能感兴趣的:(UVA)