排队领水(C++版)

8 篇文章 0 订阅

排队领水

链接:https://ac.nowcoder.com/acm/problem/22240
来源:牛客网

描述

羊村的供水系统搞砸了,隔壁牛村捐赠的的矿泉水刚刚送达,村长让喜羊羊们排队领水,已知有n个羊村村民正在排队取水,懒羊羊不知道他在队伍的具体哪个位置,但他知道有不少于a个人在他前面,有不多于b个人在他后面,你能帮忙计算一下懒羊羊有多少个可能的位置吗?

输入描述:

输入一行包含三个整数n,a,b

0<= a,b < n <= 100

输出描述:

输出一行包含一个整数表示可能的位置数

示例1

输入
3 1 1
输出
2

示例2

输入
10 1 3
输出
4

实现

需要注意的是不能设置为

n-a>=b?b+1:n-a

因为这个1加的是自身的位置,不存在于n-a的最大可能值之中

#include<iostream>
using namespace std;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
cout<<(n-a<=b?n-a:b+1);}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
窗口排队管理系统可以分为两个部分,前台和后台。前台主要是用户界面,后台则是业务处理和数据管理。 以下是一个简单的窗口排队管理系统的C++代码示例: ```cpp #include <iostream> #include <queue> using namespace std; struct Customer { string name; int number; }; queue<Customer> customers; void displayMenu() { cout << "1. Add customer to the queue" << endl; cout << "2. Serve next customer" << endl; cout << "3. Display current queue" << endl; cout << "4. Exit" << endl; cout << "Enter your choice: "; } void addCustomer() { Customer c; cout << "Enter customer name: "; cin >> c.name; c.number = customers.size() + 1; customers.push(c); cout << "Customer added to the queue." << endl; } void serveCustomer() { if (customers.empty()) { cout << "No customers in the queue." << endl; return; } Customer c = customers.front(); customers.pop(); cout << "Serving customer " << c.name << " (number " << c.number << ")." << endl; } void displayQueue() { if (customers.empty()) { cout << "No customers in the queue." << endl; return; } cout << "Current queue:" << endl; cout << "Number\tName" << endl; queue<Customer> temp = customers; while (!temp.empty()) { Customer c = temp.front(); temp.pop(); cout << c.number << "\t" << c.name << endl; } } int main() { int choice; do { displayMenu(); cin >> choice; switch (choice) { case 1: addCustomer(); break; case 2: serveCustomer(); break; case 3: displayQueue(); break; case 4: cout << "Exiting..." << endl; break; default: cout << "Invalid choice." << endl; } } while (choice != 4); return 0; } ``` 该程序使用了STL库的队列容器来管理顾客的排队顺序,可以添加新顾客、服务下一个顾客、显示当前队列和退出系统。可以根据需求进行扩展和修改。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值