Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. public class CaseAlternatorTask
  2. {
  3.     public static List<string> AlternateCharCases(string lowercaseWord)
  4.     {
  5.         var result = new List<string>();
  6.         AlternateCharCases(lowercaseWord.ToCharArray(), 0, result);
  7.         return result;
  8.     }
  9.  
  10.     static void AlternateCharCases(char[] word, int startIndex, List<string> result)
  11.     {
  12.         if(startIndex == word.Length)
  13.         {
  14.             result.Add(new string(word));
  15.             return;
  16.         }
  17.        
  18.         if (Char.IsLetter(word[startIndex]))
  19.         {
  20.             var word1 = word.ToArray();
  21.             var word2 = word.ToArray();
  22.            
  23.             word1[startIndex] = Char.ToLower(word1[startIndex]);
  24.             word2[startIndex] = Char.ToUpper(word2[startIndex]);
  25.            
  26.             AlternateCharCases(word1, startIndex+1, result);
  27.             if(word1[startIndex] != word2[startIndex])
  28.                 AlternateCharCases(word2, startIndex+1, result);
  29.         }else
  30.             AlternateCharCases(word, startIndex+1, result);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement