A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE

Answer Posted / rohit tehlan

using System;
using System.Linq;

namespace StringHighestCharacterOccur
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the character string ");
string str = Console.ReadLine();

int[] max = new int[str.Length]; // this will store occurence count for each character
for (int i = 0; i < str.Length; i++)
{
int count = 0;
for (int j = 0; j < str.Length; j++)
{
if (str[i] == str[j])
{
count++;
}
}
max[i] = count;
}
int maxvalue = max.Max();
int maxvalueindex = max.ToList().IndexOf(maxvalue); // this will give the index of character with max occurence
Console.WriteLine("Character with max occurence is: " + str[maxvalueindex]);
Console.ReadLine();
}
}
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you prove that java swing is multithreaded?

1698


how to remove header and footer in jcl using sort utility

5101


When we use Windows authentication mode

1580


without selecting individually each field in Action Class from jsp,what is the best process to select as many as field at a time automatically from jsp page by using value object class.

1436


What is the purpose of element of in Ajax

2013






Which CRM is better to opt, Sebiel CRM or Salesforce CRM or sap CRM? which institute is best one in hyderabad

1847


Suppose server object is not loaded into the memory, and the client request for it , what will happen?

2171


please any one pass file aid,xpeditor and endeavor tools

1889


8.In DSP,Define Signal and System?and various type of signals.

1554


there are N number of matchboxes numbered 1...N.each matchbox contain various number of stick.Two player can alternatevely pick some amount of stick from the higest stick containing box . The player is condidered win if there is no stick after his move.Find the final move so that the move player win. Note:In case the number of stick is equal ,pick the stick from the higest numbered box. eg: 3 box contain stick as:1,1,1. if u take 1 stick from 3rd numbred box you will any how win the match.

2428


what is best way to create a Thread class & why?

1588


in network security,how we identified threat?some one say we found threat according to it's signature,but how we get signature or pattern of the virus?

1519


Explain what is OOPS and its concepts?

582


is it acceptable if we declare multiple exceptions in same overridden method.

2110


hi this is uday i want prepare for nic exam if any one have previous question papers please send me or atlest guide me how to prepare my ID is udaykiran4u@in.com

1475