Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 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 LettersCombinations
  8. {
  9.     class LettersCombinations
  10.     {
  11.         static void Main()
  12.         {
  13.             char n1 = Convert.ToChar(Console.ReadLine());   // Start letter
  14.             char n2 = Convert.ToChar(Console.ReadLine());   // End letter
  15.             char n3 = Convert.ToChar(Console.ReadLine());   // Letter to skip
  16.  
  17.             int start = 0;
  18.             int end = 0;
  19.             long counter = 0;
  20.  
  21.             char[] charArray = "abcdefghijklmnopqrstuvwxyz".ToCharArray();  // Assigning a-z array
  22.  
  23.             for (int i = 0; i < charArray.Length - 1; i++)                  // Loop for gathering index of the start/end letters
  24.             {
  25.                 if (charArray[i] == n1)                                     // Gathering start letter index
  26.                 {
  27.                     start = i;
  28.                 }
  29.                 if (charArray[i] == n2)                                     // Gathering end letter index
  30.                 {
  31.                     end = i;
  32.                 }
  33.                 if (end != 0)                                               // Breaking the loop if end letter index is gathered
  34.                 {
  35.                     break;
  36.                 }
  37.  
  38.             }
  39.  
  40.  
  41.  
  42.             for (int i = start; i <= end; i++)                              // Combinations printing loop 1
  43.             {
  44.                 if (charArray[i] == n3)                                     // Skipping the combination containing n3
  45.                 {
  46.                     continue;
  47.                 }
  48.                 for (int j = start; j <= end; j++)                          // Combinations printing loop 1.1
  49.                 {
  50.                     if (charArray[j] == n3)                                 // Skipping the combination containing n3
  51.                     {
  52.                         continue;
  53.                     }
  54.                     for (int k = start; k <= end; k++)                      // Combinations printing loop 1.2
  55.                     {
  56.                         if (charArray[k] == n3)                             // Skipping the combination containing n3
  57.                         {
  58.                             continue;
  59.                         }
  60.                         Console.Write("{0}{1}{2} ", charArray[i], charArray[j], charArray[k]);
  61.                         counter++;
  62.                     }
  63.                 }
  64.             }
  65.  
  66.             Console.Write(counter);
  67.             Console.WriteLine();
  68.  
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement