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
what are the activities you enjoy most and How do you see these Developing in the Future with Reference to in your work life and in your personal life
EXPLAIN UNARY OPEARATORS
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)
What are the Short cut Keys of Tally ERP?
What is Negative testing?
Write code to read the records from a file and load any array of size 99?make sure that you take care of all the error conditions?
How do i find out the number of parameters passed into function?
suppose we have ten members of a physical file but we want the output of last 5 members only.how to achieve that?
what is the difference between SCAN AND CHECK,LOKUP AND XFOOT? where we can use thease opcodes? Can any body tell me real time senariao with example?
differences between qtp10.0 and 11.0 ?
If u need any fake experience certificate in software side, contact me at: vikramyadhav@gmail.com
can we extend a class having only one parameterised constructor.Suggest the process to do it.
what will we require to build project with the help of oracle
what is adodb??y it is used for connection of V.B and access??what is ado?dao?
ok how would i do the following extract from a file i have ssns = 267907230 which are in column 7 into a separate data set then create a 2nd job step to extract from the data set created the following "fund code" which is in column 31 and is 113 into yet another data set