Given 3 points a(x1,y1), b(x2, y2), c(x3, y3) check if they form a non-degenerate triangle or not. If they do form a triangle then check if points p(xp, yp) and q(xq, yq) lie inside or on the triangle.
We have to decode the string for this first step is to reverse the string and the second convert the numeric representation of ASCII to the character.
we are not given the string length so we assume it to be 10^5.
Another thing other than the ASCII value of a to z and A to Z we are also given the ASCII value of space which is 32.
Solution
Solution to this problem is quite greedy.
First, we will reverse the string reverse(str.begin(),str.end()) .
Secondly, we start traversing the string from starting and keep converting string characters into numeric form. There can be many ways to do this one of that would be num = num * 10 + (str[i] - '0');
Keep in mind that we are travelling every index one by one so we are getting one digit from 0 to 9 at one time so we need to concatenate that and also reset when we get a space
keep printing every char when the num is between range from a to Z and provide space when we encounter an ASCII value of 32 .
We are given 3 points say X(x1,y1) Y(x2,y2) Z(x3,y3) in a graph .
We need to first find if this 3-point forms a non-degenerated triangle or not (which means a triangle that has a positive area or not ).
Other than these we are given two other points coordinator says P and Q.
For point P and Q we need to check if these point lies inside the circle or not.
print 1, if p is inside the circle and q, is outside the triangle.
Print 0 if the triangle is non-degenerate
Print 2, if q is inside the triangle and p, is not
Print 3 if p,q is inside the triangle
Print 4 if none are inside.
Solution
For this solution first, we need to find if the triangle is valid or not.
For that key observation is that three points form a triangle only when they don’t lie on a straight line, that is an area formed by the triangle of these three points is not equal to zero.
Now for the points P and Q we can only say that this point lies inside a triangle we need to calculate the area of triangles X,Y, and Z says A.
Formula for this will be Area A = [ x1(y2 – y3) + x2(y3 – y1) + x3(y1-y2)]/2 .
Similarly, we will find the area for point P in respect of XYZ triangle that is A1=>PYX,A2=>PYZ,A3=> PXZ.
If P lies inside the triangle, then A1 + A2 + A3 must be equal to A.
Similar we can check this for Q and after that print the answer based on the condition.