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
hi viewers, tell me,what is scripting and programming, define and difference...pls
Given an array all of whose elements are positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array. So 3 2 7 10 should return 13 (sum of 3 and 10) or 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)
iam confused among testing ,.net and java. can anybody help me.
Find out the roles which gives access to all tables in SAP? Thanks in advance.
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)
What is BASIS
Suppose server object is not loaded into the memory, and the client request for it , what will happen?
EXPLAIN UNARY OPEARATORS
Write a program to create a process in UNIX
how many types of operating system are avaliable?
Write a program to reverse a number?
what is the BAM? where we can use it in BizTalk server?
which worker is involved in all the phases of SDLC?
Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 1 number. Find the missing number
I want to pass .pdf files as OlE Object to crystal report through VB6. Please any one guid me...