Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1467
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1467
Zero or One
Timelimit: 2
Everyone probably knows the game Zero or One (in some regions in Brazil also known as Two or One ), used to determine a winner among three or more players. For those who are unfamiliar, the game works as follows. Each player chooses a value between zero or one; prompted by a command (usually one of the contestants announces “Zero or... One!”), all participants show the value chosen using a hand: if the value chosen is one, the contestant shows a hand with an extended index finger; if the value chosen is zero, the contestant shows a hand with all fingers closed. The winner is the one who has chosen a value different from all others. If there is no player with a value different from all others (e.g. all players choose zero, or some players choose zero and some players choose one), there is no winner. Alice, Bob and Clara are great friends and play Zerinho all the time: to determine who will buy popcorn during the movie session, who will enter the swimming pool first, etc.. They play so much that they decided make a plugin to play Zerinho on Facebook. But since they don’t know how to program computers, they divided the tasks among friends who do know, including you. Given the three values chosen by Alice, Bob and Clara, each value zero or one, write a program that determines if there is a winner, and in that case determines who is the winner.
Input
TThe input contains several test cases. Each test case contains a single line, with three integers A , B and C (each one can be 0 or 1),indicating respectively the values chosen by Alice, Beto and Clara. The end of input is determined by EOF.
Output
For each test case your program must output a single line, containing a single character. If Alice is the winner the character must be ‘ A ’, if Beto is the winner the character must be ‘ B ’, if Clara is the winner the character must be ‘ C ’, and if there is no winner the character must be ‘ * ’ (asterisc).
Sample Input | Sample Output |
1 1 0 |
C |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main(void) {
int a, b, c;
while (scanf("%d %d %d", &a, &b, &c) == 3) {
if (a == b && b == c) printf("*\n");
else if (b == c && a != c) printf("A\n");
else if (a == c && b != c) printf("B\n");
else printf("C\n");
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
0 0 0
1 0 0
Output
*
A
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
using namespace std;
int main(void) {
int a, b, c;
while (cin >> a >> b >> c) {
if (a == b && b == c) cout << "*" << endl;
else if (b == c && a != c) cout << "A" << endl;
else if (a == c && b != c) cout << "B" << endl;
else cout << "C" << endl;
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
0 0 0
1 0 0
Output
*
A
#3 Code Example with Java Programming
Code -
Java Programming
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String s;
while ((s = in.readLine()) != null) {
switch (s) {
case "0 1 1":
case "1 0 0":
out.println("A");
break;
case "1 0 1":
case "0 1 0":
out.println("B");
break;
case "1 1 0":
case "0 0 1":
out.println("C");
break;
default:
out.println("*");
break;
}
}
out.close();
}
}
Copy The Code &
Try With Live Editor
Input
0 0 0
1 0 0
Output
*
A
#4 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("fs")
const lines = readFileSync("/dev/stdin", "utf8")
.split("\n")
.map((line) => line.split(" "))
const PLAYERS = ["A", "B", "C"]
function main() {
const responses = []
for (const line of lines) {
if (line.includes("")) break // EOF
if (line.every(value => value === "0") || line.every(value => value === "1")) responses.push("*")
else if (line.filter(value => value == "1").length == 1) responses.push(PLAYERS[line.indexOf("1")])
else if (line.filter(value => value == "0").length == 1) responses.push(PLAYERS[line.indexOf("0")])
}
console.log(responses.join("\n"))
}
main()
Copy The Code &
Try With Live Editor
Input
0 0 0
1 0 0
Output
*
A
#5 Code Example with Python Programming
Code -
Python Programming
while True:
try:
e = str(input()).split()
a = int(e[0])
b = int(e[1])
c = int(e[2])
if a == b == c: print('*')
elif b == c != a: print('A')
elif a == c != b: print('B')
else: print('C')
except EOFError:
break
Copy The Code &
Try With Live Editor
Input
0 0 0
1 0 0
Output
*
A