forked from Faizan-Mushtaq-Wani/Hacktoberfest-21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoinFlips.java
32 lines (31 loc) · 797 Bytes
/
CoinFlips.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
public class CoinFlips {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-- > 0){
int g=sc.nextInt();
while(g-- > 0)
{
int ans[]=new int[3];
Arrays.fill(ans,0);
int i=sc.nextInt();
int n=sc.nextInt();
int q=sc.nextInt();
if(n%2==0) System.out.println(n/2);
else if(n==1)
{
if(i==1) ans[2]=1;
else if(i==2) ans[1]=1;
System.out.println(ans[q]);
}
else
{
if(i==1) {ans[1]=n/2;ans[2]=(n/2)+1;}
else if(i==2) {ans[1]=(n/2)+1;ans[2]=n/2;}
System.out.println(ans[q]);
}
}
}
}
}