Created
September 23, 2011 22:10
-
-
Save serdarb/1238565 to your computer and use it in GitHub Desktop.
Problem 2 - Countries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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