Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ReverseWordsInString
- {
- class Program
- {
- // Task is to reverse the words in a string, as proposed by JustinLloyd
- // http://forum.unity3d.com/threads/117543-I-need-peer-reviewing-to-evaluate-my-abilities-as-a-programmer.?p=785796&viewfull=1#post785796
- // My understanding is that the key pricinciple is getting the job done in a developer efficent way, hardware be damned.
- // This correlates with my experiments, that show much 'optimisation' is irrelevant, as can be seen in my pastebin submissions such as:
- // Culling System where I opted for brute force: http://pastebin.com/sf6Gf5cM which was sufficiently powerful
- static void Main(string[] args)
- {
- var sampleData = "the cat sat on the mat"; //It is a given that the string will be 'clean' as per this sample.
- Console.WriteLine("Solution One: {0}", SolutionOne(sampleData));
- Console.WriteLine();
- Console.WriteLine("Solution Two: {0}", SolutionTwo(sampleData));
- Console.ReadLine();
- }
- //Solution one assumes the obvious - reverse the order of the words in the sentance.
- static string SolutionOne(string data)
- {
- return string.Join(" ", data.Split(' ').Reverse());
- }
- //Solution two assumes an alternate interpretation, reorder the letters in the words, not the order of the words themselves.
- static string SolutionTwo(string data)
- {
- return string.Join(" ", data.Split(' ').Select(x => new string(x.Reverse().ToArray())));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment