Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created November 8, 2016 06:18
Show Gist options
  • Save jianminchen/ef96b59d7279f1b80473519434ab959f to your computer and use it in GitHub Desktop.
Save jianminchen/ef96b59d7279f1b80473519434ab959f to your computer and use it in GitHub Desktop.
HackerRank NCR codesprint - first submission - score 15 of 50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace gameOfProjects
{
class Program
{
static void Main(string[] args)
{
process();
//testing();
}
private static void testing()
{
string test1 = calculateWinner(1, 10, 11);
string test2 = calculateWinner(7, 20, 5);
string test3 = calculateWinner(5, 10, 17);
string test4 = calculateWinner(5, 10, 21);
}
private static void process()
{
int g = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < g; i++)
{
string[] arr = Console.ReadLine().Split(' ');
int begin = Convert.ToInt32(arr[0]);
int end = Convert.ToInt32(arr[1]);
int k = Convert.ToInt32(arr[2]);
Console.WriteLine(calculateWinner(begin, end, k));
}
}
private static string calculateWinner(int begin, int end, int k)
{
string[] message = new string[2] { "Alice", "Bob" };
int winner = 0; // 0 - Alice, 1 - Bob
int startPos = begin;
int firstRange = end - begin;
int secondRange = begin;
int module = 2 * end + 1;
int res = k % module;
if (res <= end && res >= begin)
winner = 0;
if (res > end && res <= (begin + end))
winner = 1;
if (res > begin + end)
winner = 0;
return message[winner];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment