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 n, a 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。
代码:
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 int n, a, b, c, r; 7 scanf("%d%d%d", &n, &a, &b); 8 c = n-a-1; 9 if(c > b) { 10 r = b+1; 11 }else { 12 r = c+1; 13 } 14 printf("%d", r); 15 return 0; 16 }