本文共 842 字,大约阅读时间需要 2 分钟。
#include #include using namespace std; int main(){ int temp; int customers_count = 0; unsigned maxnumber = 10; //银行今天接待人数限制 queue number_line; cout << "bank only receive " << maxnumber << " people today" << endl; cout << "customers over maxnumber or input '-1' stop serving" << endl; cout << "input your number" << endl; while (cin >> temp) { if (temp == -1 || number_line.size() == maxnumber) { if (number_line.size() == maxnumber) { cout << "sorry the customers are too many! please next day comes!" << endl; } break; } number_line.push(temp); } return 0; } 通过这个简单的程序,我们可以模拟一个银行接待人数的系统。程序使用队列数据结构来管理接待的顾客数量,当达到最大值时会提示顾客下次来店。
程序的主要逻辑是:读取用户输入的数字,直到达到最大值10或用户输入-1为止。输入的数字会被添加到队列中,队列的大小限制了接待人数。当队列达到最大值时,程序会提示"抱歉,今天的人数太多了,请下次再来"。
这个程序简单实用,适合用于教学或演示队列数据结构的基本应用。
转载地址:http://mfni.baihongyu.com/