help needed to develop an algorithm [closed]
hi i need a small help to develop an algorithm.. if there is any algorithm existing please update me.
this is what i want to do.
i have 4 input text box and one out put text box. in input text box i want to give 4 characters. for an example a, a, a, b. the output textbox should give me the answer "a".
i want to check what is the most entered character in the input textbox and want to display it.
sample开发者_StackOverflow input and output required (text1,text2,text3,text4 = output)
a,a,a,a = a
a,b,a,a = a
a,a,b,b = a
a,a,b,a = a
c,c,a,c = c
this program is writing in c# with visual studio 2010 ultimate.. any good advise would be welcome....
thanks..
Ok, i'll go with another tact; pseudo code. If you can't turn this into real code, go hand your textbook back to the teacher and tell him you're not suited to his class.
define dictionary with key as 'char' and value as integer
for each textbox
read a character from textbox
increment by 1 the dictionary value associated with this character
find the highest value in the dictionary
output the associated key
If in doubt, use brute force. This means:
- set up a key-value collection that maps characters to counts
- step through your string; for each character, if it is in the collection, increase its count by 1, otherwise add it with a count of 1
- step through your collection to find the character with the highest count (remember highest-scoring character, for each entry, update remembered entry if current is better)
If your input were significantly larger (say 1000 characters), you'd have to go for a more efficient algorithm, but we're talking about four characters total.
The algorithm is very simple:
- Iterate throuht textboxes:
- Split textbox text by "," and interate throught
- if you meet 'a' increase 'symbolACounter', if you meet 'b' increase 'symbolBCounter'
- If symbolACounter > symbolBCounter, put'a' as answer, otherwise put 'b'
- Go to next text box.
EDIT:
I haven't noticed there is 'c' as input. So, instead of counters it is better to have Dictionary<char, int>
and do something like charsDictionary[currentChar]++
;
精彩评论