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


Please Help Members By Posting Answers For Below Questions

How to call a C++ function which is compiled with C++ compiler in C code?

787


What's the difference b/w Table & Templete in Smartform?

1637


5. How do you round the addition or subtraction of two numbers in assembler?

1770


what is technical system, business system, logical system in sap pi7.0

2122


Outline the two important features of a terminating recursion. Any ideas?

1680






hi all, i need ur help in preparing a sql which performs scd2, i mean i have a scd2 mapping i need a sql which can give me same result as scd2 mapping, SRC table: cust_no, loc 01 abc 02 xyz TGT table: pm_ky cust_no loc current_flag 1 01 abc Y 2 02 xyz Y cust 1 has changed his loc to xyz then it loads into TGT table as below, pm_ky cust_no loc current_flag 1 01 abc N 2 02 xyz Y 3 01 xyz Y i need sql to get the above result, hope got me question, Any suggestion will be appreciate.. thanks, Vinod

1637


I'm new to ABAP. What is Module pool in SAP?

2117


What is the difference between COM and CORBA?

723


which worker is involved in all the phases of SDLC?

1699


1.what is the vesition managment.

1674


Hi All, Can any one please send me the difference between informatica 7i and 8i versions, Thanks in advance. vinod

1529


Tag for turning an image into a hyperlink is

1834


I am looking for NIC Sample papers or any patern of questions/ syllabus plz, send me on hamid.khan135@yahoo.in Regard

1531


what is an INI file?

1591


can we use commit,rollback in triggers and how?

1496