Sabab

Sherlock

Feb 12th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.95 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 Shelock
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string s;
  14.             s = Console.ReadLine();
  15.  
  16.             if (FullString(s)=="YES")
  17.             {
  18.                 Console.WriteLine("YES");
  19.             }
  20.  
  21.  
  22.             else
  23.             {
  24.  
  25.  
  26.  
  27.                 int counter = 0;
  28.                 int[] array = new int[1000];
  29.                 for (int i = 0; i < s.Length; i++)
  30.                 {
  31.                     string subString = s.Remove(i, 1);
  32.                     //Console.WriteLine(subString);
  33.  
  34.                     char[] subCharArray = subString.ToCharArray();
  35.                     string holder = "";
  36.  
  37.                     for (int j = 0; j < subString.Length; j++)
  38.                     {
  39.                         if (!holder.Contains(subCharArray[j]))
  40.                         {
  41.                             holder = holder + subCharArray[j];
  42.                         }
  43.  
  44.                     }
  45.  
  46.  
  47.                     // Console.WriteLine(subString+" contains "+holder);
  48.  
  49.  
  50.                     char[] holderArray = holder.ToCharArray();
  51.  
  52.                     for (int j = 0; j < holder.Length; j++)
  53.                     {
  54.                         int cntLetter = 0;
  55.  
  56.                         for (int k = 0; k < subString.Length; k++)
  57.                         {
  58.                             if (holderArray[j] == subCharArray[k])
  59.                             {
  60.                                 cntLetter++;
  61.                             }
  62.                         }
  63.  
  64.                         array[j] = cntLetter;
  65.  
  66.  
  67.  
  68.  
  69.                         //   Console.WriteLine(holderArray[j]+" is "+cntLetter+" times");
  70.  
  71.  
  72.                     }
  73.  
  74.                     int arrLength = 0;
  75.                     for (int j = 0; j < holder.Length; j++)
  76.                     {
  77.                         arrLength = arrLength + 1;
  78.                         // Console.WriteLine(array[j]+" ");
  79.                     }
  80.  
  81.                     int maxNumber = array.Max();
  82.                     int minNumber = MinNumber(array, arrLength);
  83.  
  84.                     //Console.WriteLine("Max Number :"+maxNumber);
  85.                     //Console.WriteLine("Min Number :"+minNumber);
  86.  
  87.  
  88.                     if (maxNumber == minNumber)
  89.                     {
  90.                         counter++;
  91.  
  92.                     }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.                 }
  99.  
  100.  
  101.                 if (counter > 0)
  102.                 {
  103.                     Console.WriteLine("YES");
  104.                 }
  105.  
  106.                 else
  107.                 {
  108.                     Console.WriteLine("NO");
  109.                 }
  110.  
  111.  
  112.  
  113.             }
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.             Console.ReadKey();
  136.         }
  137.  
  138.  
  139.         static int  MinNumber(int[] arr, int arrLength )
  140.         {
  141.             int tem;
  142.             for (int i = 0; i < arrLength-1; i++)
  143.             {
  144.                 for (int j = i+1; j <arrLength; j++)
  145.                 {
  146.                     if (arr[i]>arr[j])
  147.                     {
  148.                         tem = arr[i];
  149.                         arr[i] = arr[j];
  150.                         arr[j] = tem;
  151.  
  152.                     }
  153.                    
  154.                 }
  155.                
  156.                
  157.             }
  158.  
  159.             int[] arr2 = arr;
  160.  
  161.             return arr[0];
  162.  
  163.         }
  164.  
  165.  
  166.         static string FullString(string s)
  167.         {
  168.  
  169.             char[] CharArray = s.ToCharArray();
  170.             string holder = "";
  171.             int[] array=new int[1000];
  172.             for (int j = 0; j < s.Length; j++)
  173.             {
  174.                 if (!holder.Contains(CharArray[j]))
  175.                 {
  176.                     holder = holder + CharArray[j];
  177.                 }
  178.  
  179.             }
  180.  
  181.  
  182.             char[] holderArray = holder.ToCharArray();
  183.  
  184.             for (int j = 0; j < holder.Length; j++)
  185.             {
  186.                 int cntLetter = 0;
  187.  
  188.                 for (int k = 0; k < s.Length; k++)
  189.                 {
  190.                     if (holderArray[j] == CharArray[k])
  191.                     {
  192.                         cntLetter++;
  193.                     }
  194.                 }
  195.  
  196.                 array[j] = cntLetter;
  197.  
  198.  
  199.  
  200.  
  201.                 //   Console.WriteLine(holderArray[j]+" is "+cntLetter+" times");
  202.  
  203.  
  204.             }
  205.  
  206.             int arrLength = 0;
  207.             for (int j = 0; j < holder.Length; j++)
  208.             {
  209.                 arrLength = arrLength + 1;
  210.                 // Console.WriteLine(array[j]+" ");
  211.             }
  212.  
  213.             int maxNumber = array.Max();
  214.             int minNumber = MinNumber(array, arrLength);
  215.  
  216.             string returnString;
  217.  
  218.             if (maxNumber==minNumber)
  219.             {
  220.                 returnString = "YES";
  221.  
  222.             }
  223.  
  224.             else
  225.             {
  226.                 returnString = "NO";
  227.             }
  228.  
  229.             return returnString;
  230.  
  231.         }
  232.  
  233.  
  234.        
  235.  
  236.     }
  237. }
Advertisement
Add Comment
Please, Sign In to add comment