anu.anssy19
BAN USERI've corrected my code, as per yesterday's comments i got to know that i understood the question in a different way.
This should be the right code.
private Dictionary<string, int> NoOfemplyeesForEachManger()
{
Dictionary<string, int> result = new Dictionary<string, int>();
Dictionary<string, string> EmployeeNManager = new Dictionary<string, string>();
EmployeeNManager.Add("GB", "GB");
EmployeeNManager.Add("JC", "GB");
EmployeeNManager.Add("AG", "JC");
EmployeeNManager.Add("JL", "JC");
EmployeeNManager.Add("FS", "JC");
foreach (KeyValuePair<string,string> pair in EmployeeNManager)
{
if (result.ContainsKey(pair.Value))
{
if (pair.Key != pair.Value)
result[pair.Value] = result[pair.Value] + 1;
}
else
{
if(pair.Key==pair.Value)
result.Add(pair.Value, 0);
else
result.Add(pair.Value, 1);
}
}
return result;
}
private bool CheckPalindrome(string inputstring)
{
bool result=false;
char[] resultchars = inputstring.ToCharArray();
Dictionary<string, int> dresult = new Dictionary<string, int>();
int count = 0;
foreach (char c in inputstring.ToUpper().ToCharArray())
{
if (dresult.ContainsKey(c.ToString()))
{
dresult[c.ToString()] = Convert.ToInt32(dresult[c.ToString()]) + 1;
}
else
{
dresult.Add(c.ToString(), 1);
}
}
if (inputstring.Length % 2 == 0)
{ //even
foreach (int i in dresult.Values)
{
if (i % 2 != 0)
{
result = false;
break;
}
result = true;
}
}
else
{ //odd
foreach (int i in dresult.Values)
{
if (i % 2 != 0)
{
count++;
}
}
if (count > 1)
result = false;
else
result = true;
}
return result;
}
The above code is in c#
- anu.anssy19 April 06, 2015private string SecondMostHighest()
{
int[] nbrs = { 1, 2, 3, 1, 2, 3, 4, 5, 2, 4, 6, 3, 4 };
Dictionary<string,int> result=new Dictionary<string,int>();
foreach (int i in nbrs)
{
if (result.ContainsKey(i.ToString()))
{
result[i.ToString()] = Convert.ToInt32(result[i.ToString()]) + 1;
}
else
{
result.Add(i.ToString(), 1);
}
}
return result.Keys.ToList()[1];
}
- anu.anssy19 April 10, 2015