Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SecretLanguage
- {
- class Program
- {
- static void Main(string[] args)
- {
- //string sentance = Console.ReadLine();
- string sentence = "neotowheret";
- //string[] words = Console.ReadLine().Split(new char[] {' ',',','\"'}, StringSplitOptions.RemoveEmptyEntries);
- string[] words = "\"one\",\"two\",\"three\",\"there\"".Split(new char[] { ' ', ',', '\"' }, StringSplitOptions.RemoveEmptyEntries);
- string[] sortedWords = new string[words.Length];
- for (int i = 0; i < words.Length; i++)
- {
- char[] unsorted = words[i].ToCharArray();
- Array.Sort(unsorted);
- sortedWords[i] = new string(unsorted);
- }
- int[] min = new int[sentence.Length + 1];
- int lenght = sentence.Length;
- for (int i = 0; i < lenght; i++)
- {
- min[i + 1] = 999999;
- }
- //read
- StringBuilder builder = new StringBuilder();
- string temp;
- string sortedTemp;
- foreach (char nextChar in sentence)
- {
- builder.Append(nextChar);
- temp = builder.ToString();
- char[] unsorted = temp.ToCharArray();
- Array.Sort(unsorted);
- sortedTemp = new string(unsorted);
- for (int i = 0; i < sortedWords.Length; i++)
- {
- int minCost = 0;
- if (sortedTemp == sortedWords[i])
- {
- int cost = 0;
- for (int j = 0; j < words[i].Length; j++)
- {
- if (temp[j] == words[i][j])
- {
- cost++;
- }
- }
- if (minCost < sortedTemp.Length - cost)
- {
- }
- }
- if (min.Length - 3 <= 0 && min[lenght - 3] != 999999)
- {
- if (min[temp.Length] > temp.Length - minCost)
- {
- min[temp.Length] = temp.Length - minCost;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment