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
Hello Experts, What is the difference between move and move corresponding exactly? please post me asap
What is the difference beween joblib and steplib statements
what is the diffrence between software and hardware language?
Q1.Write a C program which asks the user for a number between 1 to 9 and shows the number. If the user inputs a number out of the specified range, the program should show an error and prompt the user for a valid input.
When you deliver your C++ headers and C++ library of a class (what all can you change in the class so that application using your class does not need to recompile the code)
A good website has the following conditions It should be interactive. It should contain at least 20 images. Title cannot be null and should contain at least 10 letters other than spaces and hyphen (-). The keywords should contain atleast three among the following list : "design", "Graphics", "lovely", "beautiful", "amazing" and "mesmerising" Write a method: boolean isGoodWebsite(boolean isInteractive, int numOfImages, String title,String keywords[]) isInteractive whether the site is interactive or not numOfImages Number of images on the website title Title of the website keywords Array of keywords in the website.
Have you used callsymputx? what points need to be kept in mind when using it?
what is the system development cycle
how to add a new table with variables and thier values into a imported file uisng proc import?
Write a program to find duplicate number from array in minimum time complexity.
I want Ada programming language books. Could anyone post me any link for that?
Write a program to swap the content of two variables without using a third variable.
what is the similarity between networking devices?
is it possible to desable particular parameter of the normal orcle report based on some condition ?????? if yes,wht is the function for desabling a parameter...
sample and simple coding where we get?