Interviews4 answers
i have a string like "Nitin" write a method or logic to get output like this this N=2 I=2 T=1 means char count in string.
4 Answers
class Program
{
static void Main(string[] args)
{
int cnt = 0; int occ = 0;
Console.WriteLine("Enter string");
string str = Console.ReadLine();
char[] newstr = str.Distinct().ToArray();
for (int i = 0; i < newstr.Length; i )
{
cnt = 0; occ = 0;
while (cnt < str.Length)
{
if (newstr[i] == str[cnt]) { occ ; }
cnt ;
}
Console.WriteLine(" {0} = {1} ", newstr[i], occ);
}
Console.ReadLine();
}
}
Vaibhav SalwePosted May 30, 2015, 4:27 AM EDT
string str = "nitin";
var Mylsit = str.GroupBy(e => e).Select(g => new { g.Key, Count = g.Count() }).ToList();
Console.WriteLine(Mylsit[0]);
Console.WriteLine(Mylsit[1]);
Console.WriteLine(Mylsit[2]);
Pankaj Kumar ChoudharyPosted May 27, 2015, 8:59 AM EDT
Awesome Harish
Venkataramana MulumudiPosted Dec 26, 2014, 7:05 AM EST
var resultList = input.GroupBy(e => e).Select(g => new {q = g.Key.ToString().ToUpper() "-" g.Count().ToString() }).ToList();
foreach (var item in resultList)
{
Console.WriteLine(item.q);
}
Harieswaran DPosted Dec 18, 2014, 1:28 AM EST


