A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE
Answer Posted / paindriven
char HighestCharCount(const char* str)
{
const int length = strlen(str);
if (length == 0)
return ' ';
if (length == 1)
return str[0];
int indexOfHighest = int(-1);
int highestCounter = 0;
for (int i=0; i < length; ++i)
{
const int remain = length - i;
char test = str[i];
int current = 0;
for (int j=i+1; j < remain; ++j)
{
if (str[j] == test)
{
current++;
if (current > highestCounter)
{
highestCounter = current;
indexOfHighest = i;
}
}
}
}
return str[indexOfHighest];
}
| Is This Answer Correct ? | 38 Yes | 10 No |
Post New Answer View All Answers
suppose we have ten members of a physical file but we want the output of last 5 members only.how to achieve that?
how do we provide security for web services
How to call a C++ function which is compiled with C++ compiler in C code?
How can recruiter justified that the candidate is expert in Algorithm and datastructure for Software product development ?
what is diff bet ref variable & instance of class
what is the difference between uservariables and systemvariables (in Environmental variables)???
hi..this is kartheek..complted mca in 2009..but i dont have knowledge in programing..but to learn new language.. which one is suitable for me?is SAP or IBM mainframes is suitable for me..?if it suits how much will it costs..?pls answer...
how we can know the funcions available in a class recording java?
What's the difference b/w Table & Templete in Smartform?
it is a language or tools?
how to generate dsnless connectivity in j2ee
4. What is the need of START 0? Instead if can we use any other numeric? If we use what will happen?
Delta 5 weight scale not connect with oracle application what i can do?
Explain polymorphism. Provide an example.
Outline the two important features of a terminating recursion. Any ideas?