Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Kevin's C# and Linq version

  • Loading branch information...
commit b690e80f7919e26d3370e9eb1e664c37c79e7a23 1 parent 60cbd38
Ben authored
Showing with 57 additions and 0 deletions.
  1. +5 −0 c_sharp_linq_kevin/README
  2. +52 −0 c_sharp_linq_kevin/program.cs
5 c_sharp_linq_kevin/README
View
@@ -0,0 +1,5 @@
+Solution done by Kevin later that day during CodeMash
+Written in C# using Linq for most of the work
+Was much cleaner until I (Ben) pointed out that he forgot the header row in the output
+
+slightly edited from: http://bitbucket.org/kberridge/stoutsystemschallenge/
52 c_sharp_linq_kevin/program.cs
View
@@ -0,0 +1,52 @@
+using System;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+
+namespace ProgrammingContest
+{
+ public class Program
+ {
+ [STAThread]
+ public static void Main()
+ {
+ string[] lines = File.ReadAllLines( "../input.txt" );
+
+ // split lines on tab
+ var splits =
+ (from line in lines
+ select line.Split( '\t' )).Skip(1).ToArray();
+
+ // do everything
+ var output =
+ from split in splits
+ where !String.IsNullOrEmpty( split[1] )
+ orderby split[1], Convert.ToInt32( split[4] )
+ select ParseLine(split);
+
+ // join lines back with tabs
+ var joinedOutput =
+ from o in output
+ select String.Join( "\t", o );
+
+ using ( StreamWriter sw = new StreamWriter( "output.txt" ) )
+ {
+ sw.WriteLine( lines[0] );
+ foreach( var o in joinedOutput )
+ sw.WriteLine( o );
+ }
+ }
+
+ public static string[] ParseLine( string[] line )
+ {
+ var r = new Regex( "[^A-Za-z]" );
+ line[1] = r.Replace( line[1], "" );
+
+ char[] chars = line[1].ToCharArray();
+ Array.Reverse( chars );
+ line[1] = new string( chars );
+
+ return line;
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.