sashomaga

Arange words

Feb 5th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 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 SecretLanguage
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             //string sentance = Console.ReadLine();
  15.             string sentence = "neotowheret";
  16.  
  17.             //string[] words = Console.ReadLine().Split(new char[] {' ',',','\"'}, StringSplitOptions.RemoveEmptyEntries);
  18.             string[] words = "\"one\",\"two\",\"three\",\"there\"".Split(new char[] { ' ', ',', '\"' }, StringSplitOptions.RemoveEmptyEntries);
  19.             string[] sortedWords = new string[words.Length];
  20.             for (int i = 0; i < words.Length; i++)
  21.             {
  22.                 char[] unsorted = words[i].ToCharArray();
  23.                 Array.Sort(unsorted);
  24.                 sortedWords[i] = new string(unsorted);
  25.             }
  26.             int[] min = new int[sentence.Length + 1];
  27.             int lenght = sentence.Length;
  28.             for (int i = 0; i < lenght; i++)
  29.             {
  30.                 min[i + 1] = 999999;
  31.             }
  32.             //read
  33.             StringBuilder builder = new StringBuilder();
  34.             string temp;
  35.             string sortedTemp;
  36.             foreach (char nextChar in sentence)
  37.             {
  38.                 builder.Append(nextChar);
  39.                 temp = builder.ToString();
  40.                 char[] unsorted = temp.ToCharArray();
  41.                 Array.Sort(unsorted);
  42.                 sortedTemp = new string(unsorted);
  43.                
  44.                 for (int i = 0; i < sortedWords.Length; i++)
  45.                 {
  46.                     int minCost = 0;
  47.                     if (sortedTemp == sortedWords[i])
  48.                     {
  49.                         int cost = 0;
  50.                         for (int j = 0; j < words[i].Length; j++)
  51.                         {
  52.                             if (temp[j] == words[i][j])
  53.                             {
  54.                                 cost++;
  55.                             }
  56.                         }
  57.                         if (minCost < sortedTemp.Length - cost)
  58.                         {
  59.                            
  60.                         }
  61.  
  62.                     }
  63.                     if (min.Length - 3 <= 0 && min[lenght - 3] != 999999)
  64.                     {
  65.                         if (min[temp.Length] > temp.Length - minCost)
  66.                         {
  67.                             min[temp.Length] = temp.Length - minCost;
  68.                         }
  69.                     }
  70.                 }
  71.  
  72.  
  73.  
  74.  
  75.             }
  76.         }
  77.  
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment