Facebook Hacker Cup 2012 Qualifying Solution for Alphabet Soup

This is my solution for the Alphabet Soup problem, which is one of three in the Facebook Hacker Cup 2012 qualifying round.  I had forgotten about the qualifying round this weekend and I saw a post on my news feed saying 2 hours left to qualify.  I fired up a new visual studio C# command line project and knocked it out in about 30 minutes.  This can probably be optimized more but it was pretty simple.  Here is the problem set description:

This is my C# solution

My code starts off by reading the input lines from the text file one by one.  It converts the first line into an integer and sets it as the max count for my for loop.  Then it basically counts each letter I am looking for by doing a Split function and subtracting 1 from the lenth which gets me the letter count.  I divide the C count by two since “HACKERCUP” contains two Cs.  Then I run a minimum function on the integer array to find the lowest number in the counts which gives me the answer for the line.  It then writes that answer with the proper string formatting for the answer to my output text file. The program does this for each line in the input file except for the first line since it is skipped by setting my for loop to start counting at 1 instead of 0.


Donate Bitcoins
Posted Under: C#

Author

Written by Joey Iodice

I'm a software developer focusing on ASP.net, HTML5, jQuery, & Javascript.

0 Comments

No comments yet, be the first to comment.

Leave a Reply