Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Kulyash stays in room that has a single bulb and N buttons. The bulb is initially on.
The initial states of the buttons are stored in a binary string S of length N — if Si is 0, the i-th button is off, and if Si is 1, the i-th button is on. If Kulyash toggles any single button then the state of the bulb reverses i.e. the bulb lights up if it was off and vice versa.
Kulyash has toggled some buttons and the final states of the buttons are stored in another binary string R of length N. He asks you to determine the final state of the bulb.
For each test case, output on a new line the final state of the bulb (0 for off and 1 for on).
Input:
2
3
000
001
2
00
11
Output:
0
1
Test case 1: All the buttons are initially off and finally the state of only one button has changed so the state of the bulb reverses once i.e. it turns off.
Test case 2: All the buttons are initially off and finally the states of two buttons have changed so the state of the bulb reverses twice i.e. it remains on.
#include <iostream>
using namespace std;
int main() {
int t; cin >> t;
while(t--){
int n, count = 0; cin >> n;
string s,r; cin >> s >> r;
for(int i = 0; i < n; i++){
if(s[i] != r[i])
count++;
}
if(count%2 == 0){
cout << 1 << endl;
}
else{
cout << 0 << endl;
}
}
return 0;
}
/* 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) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int count=0;
String s=sc.next();
String r=sc.next();
for(int i=0;i<n;i++){
if(s.charAt(i)!=r.charAt(i)){
count++;
}
}
if(count%2==1){
System.out.println("0");
}else{
System.out.println("1");
}
}
}
}
// Scanner sc = new Scanner(System.in);
// int t = Integer.parseInt(sc.nextLine());
// while(t>0){
// int count = 0;
// int n = Integer.parseInt(sc.nextLine());
// String s = sc.nextLine();
// String r = sc.nextLine();
// for(int i=0 ; i<n ; i++){
// if(s.charAt(i)!=r.charAt(i)){
// count++;
// }
// }
// if(count%2 == 1) System.out.println(0);
// else System.out.println(1);
// t--;
// }
# cook your dish here
for i in range(int(input())):
a=int(input())
b=input()
c=input()
count=0
for j in range(len(b)):
if c[j]!=b[j]:
count+=1
if(count%2==0):
print(1)
else:
print(0)
In our experience, we suggest you solve this N Buttons 1 Bulb 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 N Buttons 1 Bulb CodeChef Solution
I hope this N Buttons 1 Bulb 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 >>