Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers n, a and b (0≤a,b<n≤100).
Print the single number − the number of the sought positions.
3 1 1
2
5 2 3
3
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
简单翻译就是排队,三个输入,一个是队伍的人数n,一个是在排在他前面不能少于a的人,另一个是排在他后面不多于b的人
输出: 他可以站的位置。
可以看第一个case input 3 1 1 他可以站2 他前面有1个人后面1个人 他可以站3 前面2个人后面没有人
idea :
1.当a>=n,则肯定没有位置供选择 则输出0
2.当a+b==n时,我们可以发现我们所能选的就是从a开始到n结束 即b个位置
3.当a+b<n时,我们可以从n-b开始到n 考虑端点就是b+1个嘛
4.当a+b>n时 且a<n,我们可以从a+1开始取,取到n,就是n-a个位置
AC:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,a,b;
cin >> n >> a >> b;
if(a+b==n)
{
cout << b;
}
else if(a+b<n)
{
cout << b+;
}
else if(a>=n)
{
cout << ;
}
else
{
cout << n-a;
} }