Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Tonmoy has a special torch. The torch has 4 levels numbered 1 to 4 and 2 states (On and Off). Levels 1,2, and 3 correspond to the On state while level 4 corresponds to the Off state.
The levels of the torch can be changed as:
Given the initial state as K and the number of changes made in the levels as N, find the final state of the torch. If the final state cannot be determined, print Ambiguous instead.
For each test case, output in a single line, the final state of the torch, i.e. On or Off. If the final state cannot be determined, print Ambiguous instead.
You may print each character of the string in uppercase or lowercase (for example, the strings On, ON, on and oN will all be treated as identical).
Input:
3
4 0
0 1
3 1
Output:
Off
On
Ambiguous
Test Case 1: Initially, the torch is in Off state. Since only level 4 corresponds to the Off state, the torch is at level 4 initially. After 4 changes, the final level would be 4. Level 4 corresponds to the Off state. Hence, finally the torch is Off.
Test Case 2: Initially, the torch is in On state. After 0 changes, the torch remains in the On state.
Test Case 3: Initially, the torch is in On state. This can correspond to any of the first 3 levels. Thus, we cannot determine the final level after 3 changes. Hence, the final state is Ambiguous.
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
// your code goes here
int t,k;
ll n;
cin>>t;
while(t--){
cin>>n>>k;
if(k==0){
if(n%4==0)
cout<<"Off"<<endl;
else
cout<<"On"<<endl;
}
else{
if(n%4==0)
cout<<"On"<<endl;
else
cout<<"Ambiguous"<<endl;
}
}
return 0;
}
# cook your dish here
t=int(input())
for i in range(t):
n,k=map(int, input().split(' '))
if( n % 4 == 0 ):
if(k==1):
print("On")
else:
print("Off")
elif( n % 4 != 0 ):
if( k == 0 ):
print("On")
elif( k == 1 ):
print("Ambiguous")
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args){
Scanner scan =new Scanner(System.in);
int t = scan .nextInt();
while(t-->0){
int n= scan.nextInt();
int k= scan.nextInt();
int a= n%4;
if(k==0){
if(a==0){
System.out.println("Off");
}
else{
System.out.println("On");
}
}
else if(k==1){
if(a==0){
System.out.println("On");
}
else{
System.out.println("Ambiguous");
}
}
}
}
}
In our experience, we suggest you solve this Dark Light CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Dark Light CodeChef Solution
I hope this Dark Light CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>