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
details description on this mantis? who is founder of this mantis?
please any one pass file aid,xpeditor and endeavor tools
< DL Compact > tag is used for
write a query that returns one row for each department and the number of employees in that department. Given two tables EMPLOYEE and DEPARTMENT, where there can be multiple employees per department.
Write a shell program to test whether a given year is leap year or not ?
Explain polymorphism. Provide an example.
What is dialog programming?
hi, all this is shoba m.c.a . i have learned abap but no oppurtunities right now as fresher , right now i want to learn any course on demand any one pls suggest me good course and institute in hyderabad
Any real time example of O2C process from taking order till creating invoice.
Explain the types of operations? Draw the figure for shift and rotate operations?
why we use abstract word in abstract window toolkit in java language.
What is ur porject Architecture? If anyone ask what i have to specify here..
how we can know the funcions available in a class recording java?
Explain what is OOPS and its concepts?
What ports must be open for DCOM over a firewall? What is the purpose of Port 135?