| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 531 人关注过本帖
标题:求速解,拜托拜托
只看楼主 加入收藏
猪v6仔
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-6-20
收藏
 问题点数:0 回复次数:0 
求速解,拜托拜托
    #include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;

#define maxsize 20
typedef int time_hour;
typedef int time_minute;


string StopName[]=
{
    {"烟台大学"},{"铁路医院"},{"长城宾馆"},
    {"北马路汽车站"},{"清泉宅"},{"火车站"}
};
int StopTime[]=
{
    9,20,9,40,10,30,10,50,11,25,11,45
};
typedef struct BUSNode
{
   
    vector<string> BusName;
    multimap<int,int> Time;
   
}BUS;
typedef struct
{//线性表定义
    BUS bus[maxsize];
    int last;
}Bus_List;

Bus_List  BusInit()
{
    Bus_List L;
    L.last =0;
    return L;
}
Bus_List BusInitlization(Bus_List L)
{//初始化线形表
    if(L.last<maxsize-1)
    {//表未满
        for(int i =0; i < ( sizeof ( StopName) / sizeof ( StopName[0]) ); ++i )
        {
            L.bus[i].BusName.push_back(StopName[i]);
            L.last++;
        }
        
        for(i=0;i<(sizeof(StopName)/sizeof(StopName[0]));++i)
            
            L.bus[i].Time.insert( make_pair ( StopTime[2*i],StopTime[2*i+1] ) );
        
    }
    return L;
}
vector<BUS> find_ret(Bus_List L,time_hour h,time_minute m)
{//查找符合条件的车站,可以直接输出!!
    vector<BUS> stop_gothrough;
    multimap<int,int>::iterator time_pos;
    for(int i=0;i<(sizeof(StopName)/sizeof(StopName[0]));++i)
    {
        
        time_pos=L.bus[i].Time.begin();
        if(  (time_pos->first) >= h && (time_pos->second) >=m)
            stop_gothrough.push_back(L.bus[i]);
        
    }
    return stop_gothrough;
}
typedef struct  
{
    BUS data[maxsize];
    int front,rear;
}Lqueue;


Lqueue LqueueInit()
{//初始化
    Lqueue StopList_queue;
    StopList_queue.front =StopList_queue.rear =0;
    return StopList_queue;
}
Lqueue push_queue(Lqueue StopList_queue,BUS stop)
{//建立循环队列    满足条件的车站入队   
    if( (StopList_queue.rear+1 )%maxsize != StopList_queue.front)
    {//队未满
        StopList_queue.rear = (StopList_queue.rear+1)%maxsize;
        StopList_queue.data[StopList_queue.rear].BusName =stop.BusName;
        StopList_queue.data[StopList_queue.rear].Time =stop.Time;
        return StopList_queue;
    }
    else
    {//队满时
        cout<<"队满!"<<endl;
        exit(0);
    }
   
}


//车站出队列
vector<BUS> pop_queue(Lqueue StopList_queue)
{
    vector<BUS> temp_bus;
    if( StopList_queue.front == StopList_queue.rear)
    {//队列为空
        
        cout<<"队列为空!"<<endl;
        exit(0);
    }
    while( StopList_queue.front != StopList_queue.rear )
    {//队列不为空时
        
        StopList_queue.front = ( StopList_queue.front+1 )%maxsize;
        temp_bus.push_back( StopList_queue.data[StopList_queue.front] );
        
    }
   
    return temp_bus;
}


bool queue_empty(Lqueue StopList_queue)
{//判队空
    return  ( (StopList_queue.rear+1)%maxsize ) ==StopList_queue.front ? true:false;
   
}



int queue_count(Lqueue LQ)
{//队列中元素个数
    return (LQ.rear-LQ.front+maxsize)%maxsize;
}
typedef struct LSNode
{//定义栈结点
    BUS data;
    struct LSNode* next;
   
}LinkedStack,*pLinkedStack;


pLinkedStack LinkedStackInit()
{//初始化
    pLinkedStack pLStack_top;
    pLStack_top =NULL;
    return pLStack_top;
   
}
pLinkedStack push_stack(pLinkedStack pLStack_top,BUS stop)
{//建立链栈    车站信息入栈   
   
   
    pLinkedStack pSN =new  LSNode ();
    pSN->data.BusName =stop.BusName;
    pSN->data.Time =stop.Time;
    pSN->next =pLStack_top;
    pLStack_top =pSN;
   
    return pLStack_top;
}


vector<BUS> pop_stack(pLinkedStack pLStack_top)
{//车站信息出栈
    vector<BUS> temp_bus;
    if(pLStack_top == NULL)
    {
        cout<<"栈空!"<<endl;
        exit(0);
    }
    while(pLStack_top!=NULL)
    {
        
        temp_bus.push_back( pLStack_top->data );
        pLinkedStack ptemp;
        ptemp=pLStack_top;
        pLStack_top=pLStack_top->next;
        free(ptemp);
        
    }
   
    return temp_bus;
}



bool stack_empty(pLinkedStack pLStack_top)
{//盘栈空
    return     pLStack_top ==NULL ?true:false;
}
Bus_List L;
static Lqueue LQ;
pLinkedStack pLinkedStack_top;

void input_information()
{
    int BusNumber;
    cout<<"输入你要乘坐的车次数:";
    cin>>BusNumber;
    if(51!=BusNumber)
    {
        cout<<"本系统待完善,只有51路车的信息!"<<endl;
        cout<<"输入你要乘坐的车次数:";
        cin>>BusNumber;
        return ;
    }
    else
    {
        L= BusInit();
        L =BusInitlization( L);
        LQ=LqueueInit();
        pLinkedStack_top=LinkedStackInit();
        
        int Stop_hour,stop_minute;
        cout<<"输入你要乘坐的51路车的时间:"<<endl;
        cout<<"输入小时数:";
        cin>>Stop_hour;
        cout<<"输入分钟数: ";
        cin>>stop_minute;
        vector<BUS> BUS_information =find_ret(L,Stop_hour,stop_minute);
        for(vector<BUS>::iterator pos=BUS_information.begin();pos!=BUS_information.end();++pos)
        {
            LQ= push_queue(LQ,*pos);
            pLinkedStack_top=push_stack(pLinkedStack_top,*pos);
            
        }
        
    }
   
}


void print_information()
{
    vector<BUS> bus1,bus2;
    if(!queue_empty(LQ))
    {
        
        bus1 =pop_queue(LQ);
        bus2 =pop_stack(pLinkedStack_top);
    }
   
    cout<<"////可以坐的车:                      ////"<<endl;
    cout<<endl;
    for(vector<BUS>::iterator pos=bus1.begin();pos !=bus1.end();++pos)
    {
        
        cout<<"车名:"<<(pos->BusName)[0]<<endl;
        multimap<int,int>::iterator map_pos;
        map_pos= pos->Time.begin();
        cout<<"到站时间:"<<map_pos->first<<":"<<map_pos->second<<endl;
        
    }
    cout<<endl;
    cout<<"////回来时可以坐的车:                ////"<<endl;
    cout<<endl;
    for( pos=bus2.begin();pos !=bus2.end();++pos)
    {
        
        cout<<"车名:"<<(pos->BusName)[0]<<endl;
        multimap<int,int>::iterator map_pos;
        map_pos= pos->Time.begin();
        cout<<"到站时间:"<<map_pos->first<<":"<<map_pos->second<<endl;
        
    }
   
   
}

int main()
{
    input_information();
    print_information();
    return 0;
}

我想知道,输入不是51时,他会直接结束,我想让他成循环,就是不是51时,让输入车次,再次输入51时,能继续运行,可我不会继续做下去,有会做的吗
搜索更多相关主题的帖子: 火车站 烟台大学 长城宾馆 include 
2012-06-20 12:05
快速回复:求速解,拜托拜托
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042081 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved