Sybatron

I5-21

Mar 25th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. using System;
  2.  
  3. namespace I5_21
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string a = Console.ReadLine();
  10.             string b = Console.ReadLine();
  11.  
  12.             if (a == b)
  13.             {
  14.                 Console.WriteLine("Възможно е!");
  15.             }
  16.             else if (a.Length < b.Length)
  17.             {
  18.                 Console.WriteLine("Не е възможно!");
  19.             }
  20.             else
  21.             {
  22.                 char[] letters = new char[a.Length];
  23.                 for (int i = 0; i < a.Length; i++)
  24.                 {
  25.                     letters[i] = a[i];
  26.                 }
  27.  
  28.                 bool isWordFound = true;
  29.                 for (int i = 0; i < b.Length; i++)
  30.                 {
  31.                     int index = a.IndexOf(b[i]);
  32.                     if (index != -1)
  33.                     {
  34.                         if (letters[index] != '0')
  35.                         {
  36.                             letters[index] = '0';
  37.                         }
  38.                         else
  39.                         {
  40.                             bool letterFound = false;
  41.                             index = a.IndexOf(b[i], index + 1);
  42.                             while (index != -1)
  43.                             {
  44.                                 if (letters[index] != '0')
  45.                                 {
  46.                                     letters[index] = '0';
  47.                                     letterFound = true;
  48.                                     break;
  49.                                 }
  50.                                 index = a.IndexOf(b[i], index + 1);
  51.                             }
  52.                             if (letterFound == false)
  53.                             {
  54.                                 Console.WriteLine("Не е възможно!");
  55.                                 isWordFound = false;
  56.                                 break;
  57.                             }
  58.                         }
  59.                     }
  60.                     else
  61.                     {
  62.                         Console.WriteLine("Не е възможно!");
  63.                         isWordFound = false;
  64.                         break;
  65.                     }
  66.                 }
  67.                 if (isWordFound == true)
  68.                 {
  69.                     Console.WriteLine("Възможно е!");
  70.                 }
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment