Codechef : Problem name " Favourite Numbers" solution in C#
===========================Solution code in C#==========================
using System;
public class Test
{
public static void Main()
{
int t=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<t;i++){
int A=Convert.ToInt32(Console.ReadLine());
if(A%2==0 && A%7==0)
Console.WriteLine("Alice");
else if(A%2!=0 && A%9==0)
Console.WriteLine("Bob");
else
Console.WriteLine("Charlie");
}
}
}
===================Explanation======================
As per condition, if number is even and is multiple of 7 then Alice will accept the number
If number is odd and multiple of 9 then it will be accepted by Bob
If the number is not satisfied by Alice and Bob then Charlie will take the number
Comments
Post a Comment