Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CaseAlternatorTask
- {
- public static List<string> AlternateCharCases(string lowercaseWord)
- {
- var result = new List<string>();
- AlternateCharCases(lowercaseWord.ToCharArray(), 0, result);
- return result;
- }
- static void AlternateCharCases(char[] word, int startIndex, List<string> result)
- {
- if(startIndex == word.Length)
- {
- result.Add(new string(word));
- return;
- }
- if (Char.IsLetter(word[startIndex]))
- {
- var word1 = word.ToArray();
- var word2 = word.ToArray();
- word1[startIndex] = Char.ToLower(word1[startIndex]);
- word2[startIndex] = Char.ToUpper(word2[startIndex]);
- AlternateCharCases(word1, startIndex+1, result);
- if(word1[startIndex] != word2[startIndex])
- AlternateCharCases(word2, startIndex+1, result);
- }else
- AlternateCharCases(word, startIndex+1, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement