Created
November 5, 2012 09:46
-
-
Save walterhuangsz/4016365 to your computer and use it in GitHub Desktop.
Reading by Amazing String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AmazingString | |
{ | |
class Program | |
{ | |
private static Random random = new Random(); | |
static void Main(string[] args) | |
{ | |
string sentence = "Covariant and contravariant generic type parameters provide greater flexibility in assigning and using generic types"; | |
string[] wordList = sentence.Split(); | |
StringBuilder builder = new StringBuilder(); | |
for (int i = 0; i < wordList.Length; i++) | |
{ | |
wordList[i] = amazingWord(wordList[i]); | |
builder.Append(" "); | |
builder.Append(wordList[i]); | |
} | |
Console.WriteLine(builder.ToString()); | |
Console.ReadKey(); | |
} | |
private static string amazingWord(string word) | |
{ | |
int length = word.Length; | |
if (length > 3) | |
{ | |
char[] wordLetters = word.ToCharArray(); | |
int count = length - 2; | |
while (--count > 0) | |
{ | |
int k = random.Next() % count; | |
char temp = wordLetters[k + 1]; | |
wordLetters[k + 1] = wordLetters[count + 1]; | |
wordLetters[count + 1] = temp; | |
} | |
return new string(wordLetters); | |
} | |
else | |
{ | |
return word; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment