ezayak
BAN USERC#
static int CountEmpl(string Manager, Dictionary<string,string> employees, Dictionary<string,int> result)
{
if (result.ContainsKey(Manager))
{
return result[Manager];
}
if (!employees.ContainsValue(Manager)) return 0;
int empl_number = 0;
foreach (var item in employees)
{
if (item.Value == Manager & item.Value != item.Key)
{
empl_number++;
empl_number = empl_number + CountEmpl(item.Key, employees, result);
}
}
result.Add(Manager, empl_number);
return empl_number;
}
static void Main(string[] args)
{
Dictionary<string, string> employees = new Dictionary<string, string>()
{
{ "A","C" },
{ "B","C" },
{ "D","E" },
{ "C","E" },
{ "E","F" },
{ "F","F" }
};
foreach (var item in employees)
{
System.Console.WriteLine(" {0} - {1} ", item.Key, item.Value);
}
System.Console.WriteLine("-----------------------------------------");
Dictionary<string, int> result = new Dictionary<string, int>();
foreach (var item in employees)
{
CountEmpl(item.Value, employees, result);
}
foreach (var item in result)
{
System.Console.WriteLine(" {0} - {1} ", item.Key, item.Value);
}
System.Console.ReadLine();
}
My version C#
public static string GenerateLowestNumber(string number, int n)
{
string current_string;
string outcome = "";
current_string = number;
for (int count = 1; count <= n; count++)
{
int StringLength = current_string.Length - (n - count);
char min_char = '9';
int min_index = 0;
for (int char_num = 0; char_num < StringLength; char_num++)
{
if (min_char > current_string[char_num])
{
min_char = current_string[char_num];
min_index = char_num;
}
}
outcome = outcome + min_char;
current_string = current_string.Substring(min_index + 1);
}
return outcome;
}
- ezayak April 17, 2015