The number of positions

Description

The number of positions
time limit per test: 0.5 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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.

Input

The only line contains three integers na and b (0 ≤ a, b < n ≤ 100).

Output

Print the single number — the number of the sought positions.

Sample test(s)

input
3 1 1
output
2
input
5 2 3
output
3

题解:Petr站在一个n人的队列里,已知站在他前面的人不少于a,站在他后面的人不多于b,求Petr站位的所有可能数目。

判断n-a和b的大小关系,如果前者大,考虑b,否则,考虑n-a。

代码:

 #include <stdio.h>
#include <stdlib.h> int main()
{
int n, a, b, c, r;
scanf("%d%d%d", &n, &a, &b);
c = n-a-;
if(c > b) {
r = b+;
}else {
r = c+;
}
printf("%d", r);
return ;
}

Problem -124A - Codeforces

转载请注明出处:http://www.cnblogs.com/michaelwong/p/4116499.html

上一篇:C/S模式下的打印方法


下一篇:C#根据身份证获取身份证信息以及(一级)身份证各省级*的代码