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
5. How do you round the addition or subtraction of two numbers in assembler?
how to display xisheet in list box in c# .net
which book we learned this mantis? how many version are realsed this mantis upto now?
How will you prove that java swing is multithreaded?
how can i split string in a textbox in windows appication using C#.net
1. Write a program to create a sentence at runtime and count number of vowels in it ? 2. Write a program to get a string and to convert the 1st letter of it to uppercase ?
Hi..Am done with my Masters recently..Am planning to learn TIBCO.. could anyone suggest me about how the job market will be and Is there any course necessary to learn prior to Tibco..i mean any prerequisite. I dnt have any knowledge on PL/SQL thats it... Plz suggest me in a best way...
EXPLAIN UNARY OPEARATORS
what is log files in qtp what is use
How to get the index of the clicked field in reports in ABAP?
what is adodb??y it is used for connection of V.B and access??what is ado?dao?
How to call dll API sub routine in VB Form.
What is the difference beween joblib and steplib statements
What is web.configuration? how is it work? & wht is use this?
Outline the two important features of a terminating recursion. Any ideas?