求渡口管理问题的算法

2022-01-26 02:02 点击:288 编辑:邮轮网

#include<queue>
#include<iostream>
#include<sstream>
using namespace std;

int main()
{
queue<string> q_keche, q_huoche;
string input_data, huoche=huoche, keche=keche;
int Max=10;
int k=0,h=0;

while (cin>>input_data)
{
stringstream out;
if (input_data == huoche)
{
cout <<huoche size before adding: <<q_huoche.size()<< ;
out<<(++h);
q_huoche.push(huoche+out.str());
cout <<q_huoche.back()<< in the queue, total huoche: <<q_huoche.size()<< <<endl;
}
else if (input_data == keche)
{
cout <<Keche size before adding: <<q_keche.size()<< ;
out<<(++k);
q_keche.push(keche+out.str());
cout <<q_keche.back()<< in the queue, total keche: <<q_keche.size()<< <<endl;
}
else break;

}

cout <<2 queues info:\nTotal Keche Size: <<q_keche.size()<<endl
<<Toatl Huoche Size: <<q_huoche.size()<<endl;

if ( q_keche.empty() && (!q_huoche.empty()))
while (!q_huoche.empty())
{
cout<<huoche Size: <<q_huoche.size()
<<huoche will load on the ship: <<q_huoche.front()<<endl;
q_huoche.pop();
--Max;
if (Max<=0){
cout<<The ship is full. Please wait for next ship!!!\n...\n..\n.\n
<<The ship is coming, start loading\n;
Max=10;
}
}
else
{
while ((!q_keche.empty() || !q_huoche.empty()))
{
for (int i=0; !q_keche.empty()&& i<4; i++) {
cout<<Keche Size: <<q_keche.size()<<
<<q_keche.front()<< will load on the ship: <<q_keche.front()<<endl;
q_keche.pop();
cout<<Keche Sizes after loading: <<q_keche.size()<<endl;
--Max;
}
if (!q_huoche.empty())
{
cout<<huoche Size: <<q_huoche.size()<<
<<q_huoche.front()<< huoche will load: <<q_huoche.front()<<endl;
q_huoche.pop();
cout <<huoche Sizes after loading: <<q_huoche.size()<<endl;
--Max;
}

if (Max<=0){
cout<<The ship is full. Please wait for next ship!!!\n...\n..\n.\n
<<The ship is coming, start loading\n;
Max=10;

}

}
}
}

顶一下
(0)
0%
踩一下
(0)
0%
下一篇:安徽省道路运输管理条例 内容有什么?
上一篇:特殊旅客乘机有哪些规定?