• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            把握命運,追逐夢想

            對自己所做的事要有興趣,同時還要能夠堅持不懈

            統計

            留言簿(1)

            閱讀排行榜

            評論排行榜

            C++練習5作業

            //train.h
            #pragma once
            #include
            "stdafx.h"

            class Train
            {
            public:
                Train(
            int seatNum);
                
            virtual ~Train(void);

                
            bool sellOneTicket(int p[]);
                
            bool sellTwoTickets(int p[]);
                
            bool sellThreeTickets(int p[]);
                
            bool sellFourTickets(int p[]);
            private:
                
            int *m_pSeat;
                
            int m_seatNum;
                
            int m_leavingSeat;
            }
            ;
            //TicketSell.h
            #pragma once
            #include
            "Train.h"
            #include
            "func.h"
            // stdafx.h : 標準系統包含文件的包含文件,
            // 或是經常使用但不常更改的
            // 特定于項目的包含文件
            //

            #pragma once

            #include 
            "targetver.h"

            #include 
            <stdio.h>
            #include 
            <tchar.h>
            #include
            <memory.h>



            // TODO: 在此處引用程序需要的其他頭文件
            #include <iostream>
            #include 
            <fstream>
            #include 
            <vector>
            #include 
            <string>
            #include 
            <algorithm>
            using namespace std;
            //func.h
            #pragma once
            #include
            "stdafx.h"

            bool GetRequest(int *p);
            void OutputResult(int * SeatNum, int Count);
            //func.cpp

            #include
            "func.h"

            bool GetRequest(int *p)
            {
                
            static bool first = true;
                
            static string from = "d:\\request.txt";
                
            static ifstream is(from.c_str());
                
            static istream_iterator <int> ii(is);
                
            static istream_iterator <int> eos;
                
            static vector<int> b(ii,eos);
                
            static vector< int>::iterator it  = b.begin();
                
            if(it == b.end()) return false;
                
            *= *(it++);
            return true;
            }

            void OutputResult(int * SeatNum, int Count)
            {
                
            string to = "d:\\result.txt";
                ofstream os(to.c_str(),ios_base::app);
                ostream_iterator 
            <int> oi(os ,",");
                vector
            < int> ov(SeatNum,SeatNum + Count);
                os 
            << endl<<"======================="<<endl;
                copy(ov.begin(),ov.end(),oi);
            }

            // TicketSell.cpp : 定義控制臺應用程序的入口點。
            //

            #include
            "TicketSell.h"
            #include
            "stdafx.h"

            void funcmain();

            int _tmain(int argc, _TCHAR* argv[])
            {
                
                funcmain();
                
            return 0;
            }


            void funcmain()
            {
                Train train(
            80);
                
            int num = 0;

                
            if(!GetRequest(&num))
                
            {
                    cout
            <<"wrong"<<endl;
                }

            }


            //Train.cpp
            #include "Train.h"

            Train::Train(
            int seatNum)
            {
                seatNum 
            = seatNum - seatNum%8;             //車廂座位自動向下調整為8的倍數
                this->m_seatNum = seatNum;
                
            this->m_leavingSeat = seatNum;
                
            this->m_pSeat = new int[seatNum];
                memset(
            this->m_pSeat,0,this->m_seatNum*sizeof(int));
                
            }


            Train::
            ~Train(void)
            {
                delete[] 
            this->m_pSeat;
            }



            bool Train::sellOneTicket(int p[])
            {
                
            if(this->m_leavingSeat == 0)
                    
            return false;
                
            for(int i = 0; i < this->m_seatNum; i++)
                
            {
                    
            if(this->m_pSeat[i] == 0)
                    
            {
                        
            this->m_pSeat[i] = 1;
                        
            this->m_leavingSeat--;
                        
            *= i+1;
                        
            return true;
                    }

                }

                
            return true;
            }


            bool Train::sellTwoTickets(int p[])
            {
                
            if(this->m_leavingSeat <2)
                    
            return false;
                
            for(int i = 0; i < this->m_seatNum; i+=2)
                
            {
                    
            if(this->m_pSeat[i] == 0 && this->m_pSeat[i+1]==0)
                    
            {
                        
            this->m_pSeat[i] = 1;
                        
            this->m_pSeat[i+1= 1;
                        
            this->m_leavingSeat-=2;
                        p[
            0= i+1;
                        p[
            1= i+2;
                        
            return true;
                    }

                }

                
            for(int i = 0, j = 0; i < this->m_seatNum && j <2; i++)
                
            {
                    
            if(this->m_pSeat[i] == 0 )
                    
            {
                        
            this->m_pSeat[i] = 1;
                        
            this->m_leavingSeat--;
                        p[j] 
            = i+1;
                        j
            ++;
                    }

                }

                
            return true;
            }


            bool Train::sellThreeTickets(int p[])
            {
                
            if(this->m_leavingSeat < 3)
                    
            return false;
                
            for(int i = 0; i < this->m_seatNum; i+=8)
                
            {
                    
            if(this->m_pSeat[i] + this->m_pSeat[i+1+ this->m_pSeat[i+4+ this->m_pSeat[i+5< 2)
                    
            {
                        
            for(int j = 0, k = 0; j < 6 && k<3; )
                        
            {
                            
            if(this->m_pSeat[i+j] == 0)
                            
            {
                                
            this->m_pSeat[i+j] = 1;
                                
            this->m_leavingSeat--;
                                p[k]
            = i+j+1;
                                k
            ++;
                            }

                            
            if(j%2 == 0)
                            
            {
                                j
            ++;
                            }

                            
            else
                            
            {
                                j
            +=3;
                            }


                        }

                        
                    }

                    
            return true;
                }

                
            for(int i = 0, j = 0; i < this->m_seatNum && j <3; i++)
                
            {
                    
            if(this->m_pSeat[i] == 0 )
                    
            {
                        
            this->m_pSeat[i] = 1;
                        
            this->m_leavingSeat--;
                        p[j] 
            = i+1;
                        j
            ++;
                    }

                }

                
            return true;

            }

            bool Train::sellFourTickets(int p[])
            {
                
            if(this->m_leavingSeat < 4)
                    
            return false;
                
            for(int i = 0; i < this->m_seatNum; i+=8)
                
            {
                    
            if(this->m_pSeat[i] == 0 && this->m_pSeat[i+1]==0 && this->m_pSeat[i+4]==0 && this->m_pSeat[i+5]==0)
                    
            {
                        
            this->m_pSeat[i] = 1;
                        
            this->m_pSeat[i+1= 1;
                        
            this->m_pSeat[i+4]= 1;
                        
            this->m_pSeat[i+5]= 1;
                        
            this->m_leavingSeat-=4;
                        p[
            0= i+1;
                        p[
            1= i+2;
                        p[
            2]= i+5;
                        p[
            3= i+6;
                        
            return true;
                    }

                    
            if(this->m_pSeat[i+2== 0 && this->m_pSeat[i+3]==0 && this->m_pSeat[i+6]==0 && this->m_pSeat[i+7]==0)
                    
            {
                        
            this->m_pSeat[i+2= 1;
                        
            this->m_pSeat[i+3= 1;
                        
            this->m_pSeat[i+6]= 1;
                        
            this->m_pSeat[i+7]= 1;
                        
            this->m_leavingSeat-=4;
                        p[
            0= i+3;
                        p[
            1= i+4;
                        p[
            2]= i+7;
                        p[
            3= i+8;
                        
            return true;
                    }

                }

                
            for(int i = 0, j = 0; i < this->m_seatNum && j <4; i++)
                
            {
                    
            if(this->m_pSeat[i] == 0 )
                    
            {
                        
            this->m_pSeat[i] = 1;
                        
            this->m_leavingSeat--;
                        p[j] 
            = i+1;
                        j
            ++;
                    }

                }

                
            return true;

            }

            posted on 2009-08-20 12:05 把握命運 閱讀(263) 評論(0)  編輯 收藏 引用

            99久久99久久久精品齐齐| 精品乱码久久久久久久| 久久精品亚洲男人的天堂| 久久久久亚洲AV无码专区网站| 午夜精品久久久久成人| 漂亮人妻被黑人久久精品| 久久精品国产免费| 久久夜色撩人精品国产小说| 亚洲午夜久久久影院| 中文精品久久久久国产网址| 久久综合偷偷噜噜噜色| 韩国无遮挡三级久久| 婷婷久久综合| 久久精品国产91久久麻豆自制 | 国内精品久久久久国产盗摄| 亚洲日本久久久午夜精品| 国产精品久久久久久影院| 伊人久久大香线蕉综合网站| 国产精品久久成人影院| 久久人人爽人人爽人人片AV不| 亚洲国产精品久久| 国产V亚洲V天堂无码久久久| 国内精品伊人久久久影院| 精品国产乱码久久久久久浪潮| 成人资源影音先锋久久资源网| 亚洲精品国产字幕久久不卡| 日韩精品无码久久一区二区三 | 久久影院亚洲一区| 色综合久久久久网| 国产精品毛片久久久久久久 | 色婷婷久久综合中文久久蜜桃av| 久久久久国产视频电影| 9999国产精品欧美久久久久久| 国产精品久久久久AV福利动漫| 亚洲午夜久久久久久久久久| 国内精品人妻无码久久久影院导航| 伊色综合久久之综合久久| 国产精品一区二区久久精品涩爱 | 麻豆成人久久精品二区三区免费| 亚洲午夜福利精品久久| 亚洲七七久久精品中文国产|