simonradev

LettersCombinations

Mar 12th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace NestedLoopsDemo
  8. {
  9.     class LettersCombinations
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             char startChar = char.Parse(Console.ReadLine());
  14.             char endChar = char.Parse(Console.ReadLine());
  15.             char bannedChar = char.Parse(Console.ReadLine());
  16.  
  17.             int printCount = 0;
  18.             for (char i = startChar; i <= endChar; i++)
  19.             {
  20.                 for (char j = startChar; j <= endChar; j++)
  21.                 {
  22.                     for (char k = startChar; k <= endChar; k++)
  23.                     {
  24.                         bool wordIsValid = i != bannedChar &&
  25.                                            j != bannedChar &&
  26.                                            k != bannedChar;
  27.  
  28.                         if (!wordIsValid)
  29.                         {
  30.                             continue;  
  31.                         }
  32.  
  33.                         Console.Write($"{i}{j}{k} ");
  34.                         printCount++;
  35.                     }
  36.                 }
  37.             }
  38.  
  39.             Console.WriteLine(printCount);
  40.         }
  41.     }
  42. }
Add Comment
Please, Sign In to add comment