Algorithm
Problem Name: beecrowd | 2721
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2721
Indecision of Reindeers
By Francisco Elio Parente Arcos Filho, UEA Brazil
Timelimit: 1
This year Santa's Reindeers decided that Rudolph would no longer be the one who would always be ahead. They would choose, at a fair way, who would lead the sled. And nothing is fairer than chance.
Then they decidied the following way to choose: Each Reindeer would do as many snowballs as he wanted without the others seeing. Then all the snowballs of all the Reindeers would be gathered into a single large pile. Lastly, the snowballs would be drawn from this stack one by one, and distributed among them always following the order: Dasher, Dancer, Prancer, Vixen, Comet, Cupid, Donner, Blitzen, and Rudolph. Until the snowballs were gone. The reindeer that got the last snowball would be declared the winner and would be in the main sled position this year.
Given the number of snowballs made by each Reindeer, determine which Reindeer won the draw.
Input
The input is composed of a single line containing 9 integers Ai (1 ≤ Ai ≤ 104).
Output
The output consists of a single line containing the name of the winning Reindeer.
Input Sample | Output Sample |
1 2 3 4 5 6 7 8 9 |
Rudolph |
9 9 9 9 9 9 9 9 7 |
Donner |
1 2 1 2 1 2 1 2 1 |
Vixen |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
char *renas[] = {"Dasher", "Dancer", "Prancer", "Vixen", "Comet", "Cupid", "Donner", "Blitzen", "Rudolph"};
int main(int argc, char **argv)
{
int x;
int soma = 0;
for (int i = 0; i < 9; ++i)
scanf("%d", &x), soma += x;
printf("%s\n", renas[(soma - 1) % 9]);
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<string>
#include<list>
using namespace std;
#define ll long long
#define input scanf
#define output printf
#define Loop while
#define echo cout
#define ret return
#define MAX 999999999999999999
#define MIN 0
#define PI 3.1415
vector < string> a;
void sieve();
string toBinary(int n);
bool findingSubString(string a,string b);
int main(int argc, char** argv) {
//freopen("c.txt","w",stdout)
sieve();
int a;
ll sum=0;
for(int i = 0; i < 9; i++)
{
cin >> a;
sum+=a;
}
cout << ::a[sum%9] << endl;
ret 0;
}
void sieve()
{
a.push_back("Rudolph");a.push_back("Dasher");
a.push_back("Dancer");a.push_back("Prancer");
a.push_back("Vixen");a.push_back("Comet");
a.push_back("Cupid");a.push_back("Donner");
a.push_back("Blitzen");
return;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Java Programming
Code -
Java Programming
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Locale;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.useLocale(Locale.ENGLISH);
Locale.setDefault(new Locale("en", "US"));
String entrada = sc.nextLine();
String[] entra = entrada.split(" ");
List < Integer> intList = new ArrayList();
for (String s : entra)
intList.add(Integer.valueOf(s));
int soma=0;
for (int x : intList) soma+=x;
//System.out.println(soma);
String[] nomes = {"Dasher", "Dancer", "Prancer", "Vixen", "Comet", "Cupid", "Donner", "Blitzen", "Rudolph"};
int resto = soma % 9;
//System.out.println(resto);
if (resto==0) System.out.println("Rudolph");
else System.out.println(nomes[resto-1]);
sc.close();
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("node:fs")
const input = readFileSync("/dev/stdin", "utf8")
.split(" ", 9)
.map(value => Number.parseInt(value, 10))
const CHRISTMAS_REINDEER_NAMES = [
"Dasher",
"Dancer",
"Prancer",
"Vixen",
"Comet",
"Cupid",
"Donner",
"Blitzen",
"Rudolph"
]
const reindeerName = CHRISTMAS_REINDEER_NAMES[input.reduce((sum, value) => sum + value, -1) % CHRISTMAS_REINDEER_NAMES.length]
console.log(reindeerName)
Copy The Code &
Try With Live Editor
Input
Output