Where is Vasya?
Vasya stands in line with number of people p (including Vasya)
, but he doesn ' t know exactly which position he occupies. He can say that there is no less than b
people standing in front of him and people standing behind him no more than a
. Find the number of different positions Vasya can occupy.
Input
As an input you have 3 numbers:
1. Total amount of people in the line;
2. Number of people standing in front of him
3. Number of people standing behind him
Examples
Line.whereishe (3, 1, 1)//= 2 The possible positions Are:2 and 3
Line.whereishe (5, 2, 3)//= 3 The possible positions Are:3, 4 and 5
The third parameter are not irrelavant and are the reason why (9,4,3) are 4 not 5
You have to satisfy both conditions
no less than bef people in front of him
and
no more than aft people behind him
As far as I can tell all the test cases is correct
9 people, not less than 4 people in front, not more than 3 people behind, can occupy 6,7,8,9 is a position
The fifth position, although the front is 4 people, but the back is also 4 people. After the number of people over 3, it does not fit.
usingSystem; Public classLine { Public Static intWhereishe (intPintBEF,intaft) { //Your code is here ... intCount=0; intA=0;//people infront of him intb=0;//people behind him for(intI=1; i<=p;i++) {a=i-1; b=p-i; if(a>=bef&&b<=aft) {Count++; } } returncount; } }
After using LINQ for simplification:
using System; using System.Linq; Public Static int Whereishe (intintint , aft) {return enumerable.range (1 1 >= bef && p-x <= aft). Count ();}
Other people's Solution
using System; Public class Line { publicstaticint whereishe (intint bef,int aft) { return math.min (p-bef,aft+1); } }
Where is Vasya?