Advertisement
Guest User

Untitled

a guest
May 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _14.MagicLetter
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Write a program, which prints all 3-letter combinations, using only the letters from a given interval.
  10.             //You will also receive a third letter. Every combination, which contains this letter should not be printed.
  11.  
  12.             //Examples:
  13.             //input : a c b
  14.             //output: aaa aac aca acc caa cac cca ccc
  15.  
  16.        
  17.             char letter1 = char.Parse(Console.ReadLine());
  18.             char letter2 = char.Parse(Console.ReadLine());
  19.             //letter3 is the letter which shouldn't be printed if the sequence contains it.
  20.             char letter3 = char.Parse(Console.ReadLine());
  21.  
  22.             //letter3 to string, so I can use the .contains method at the end.
  23.             string forbiddenLetter = letter3.ToString();
  24.  
  25.  
  26.             for (char i = letter1; i <= letter2; i++)
  27.             {
  28.                 for (char j = letter1; j <= letter2; j++)
  29.                 {
  30.                     for (char l = letter1; l <= letter2; l++)
  31.                     {
  32.                         //the fore-mentioned sequence of letters to be printed.
  33.                         string sequence = $"{i}{j}{l}";
  34.  
  35.                         if (sequence.Contains(forbiddenLetter))
  36.                         {
  37.  
  38.                         }
  39.                         else
  40.                         {
  41.                             Console.Write(sequence + " ");
  42.                         }
  43.  
  44.  
  45.  
  46.                     }
  47.  
  48.  
  49.                 }
  50.             }
  51.         }
  52.  
  53.  
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement