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
How to call a C++ function which is compiled with C++ compiler in C code?
What's the difference b/w Table & Templete in Smartform?
5. How do you round the addition or subtraction of two numbers in assembler?
what is technical system, business system, logical system in sap pi7.0
Outline the two important features of a terminating recursion. Any ideas?
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
I'm new to ABAP. What is Module pool in SAP?
What is the difference between COM and CORBA?
which worker is involved in all the phases of SDLC?
1.what is the vesition managment.
Hi All, Can any one please send me the difference between informatica 7i and 8i versions, Thanks in advance. vinod
Tag for turning an image into a hyperlink is
I am looking for NIC Sample papers or any patern of questions/ syllabus plz, send me on hamid.khan135@yahoo.in Regard
what is an INI file?
can we use commit,rollback in triggers and how?