Skip to content

Instantly share code, notes, and snippets.

@serdarb
Created September 23, 2011 22:10
Show Gist options
  • Save serdarb/1238565 to your computer and use it in GitHub Desktop.
Save serdarb/1238565 to your computer and use it in GitHub Desktop.
Problem 2 - Countries
using System;
using System.Text.RegularExpressions;
namespace DirectoryProblem
{
class Program
{
static void Main(string[] args)
{
string T = Console.ReadLine().Trim();
int t = 0;
if (int.TryParse(T, out t))
{
if (t >= 0 && t <= 300)
{
for (int i = 0; i < t; i++)
{
string country = Console.ReadLine().Trim();
if (country.Length > 2 && country.Length < 21)
{
Regex rgxCountry = new Regex("[A-Z]+[a-z]*");
if (rgxCountry.IsMatch(country))
{
string ending = "nobody";
if (country == "Mollaristan")
{
ending = "king";
}
else if (country == "Auritania")
{
ending = "queen";
}
Console.WriteLine(string.Format("Case #{0}: {1} is ruled by {2}", i + 1, country, ending));
}
else
{
Console.WriteLine("Country name Must start with a capital letter and all the other chars must be lower case ...");
}
}
else
{
Console.WriteLine("Country name lenght Must be between 3 and 20...");
}
}
}
else
{
Console.WriteLine("T Must be between 0 and 300...");
}
}
else
{
Console.WriteLine("You Must Enter an Integer for T...");
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment