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
What is the use of Differ interface check box in Ship confirm?
Hey this is venkatesh.Please can any body tell me what is SFLNXTCHG?where we use this keyword?what perpuse we use this?Can you tell me in real time senario with example? And in 7 specification(RPG/400)what is the mandatory specification using programs?
what is the extension of SPDS Dynamic cluster tables?
what is the diffrence between software and hardware language?
Is buffer size and file block size is similar? If similar,at which case it will be same size?
what is delimiter in sas ?
How to connect the .accdb database file of microsoft access to the Visual Basic 6.0 forms?
what is best way to create a Thread class & why?
hi i am jyoti i have done sap training in sd and master degree in economics have 2 year exp as enduser in (gdms)and 1 year as sd consultant.as contract basis now what i can do for getting job in it industry
qtp 9.2 14 days demo version was expired.I uninstalled how to reinstall this again
1) How can u create the table?
Compare any 4 software development life cycle paradigms with each other. Indicate at least one application for each of the paradigms that are suitable to developed using that paradigm.
shall we execute our java programmes in jre
How does the type system works when there is interoperability between a COM and .Net, i mean what exactly happens there
What is autocall macro and how to create autocall macro? what is the use of it?