Advertisement
akass

Genomev2

Nov 11th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.39 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 Test2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             List<string> coll = new List<string>();
  15.             for (int i = 0; i < args.Length; i++)
  16.             { coll.Add(args[i]); }
  17.  
  18.             string s = Genome.GetConcatGenom(coll);
  19.             Console.WriteLine(s);
  20.             Console.ReadKey();
  21.             //GetConcatGenom(coll);
  22.  
  23.         }
  24.     }
  25.     class Genome
  26.     {
  27.      public  static  string GetConcatGenom(List<String> genoms)
  28.         {
  29.            
  30.             return ConcatRecursive("", genoms);
  31.            
  32.         }
  33.  
  34.        static string ConcatRecursive(string s, List<String> genoms)
  35.         {
  36.            
  37.             List<String> gens = new List<String>(genoms);
  38.             if (genoms.Count == 1)
  39.             {
  40.                 return s;
  41.             }
  42.            
  43.                 foreach (var gen in gens)
  44.                 {
  45.                     string newgen = s + "";
  46.                     //if (genoms.Count == 0) { return newgen ; }
  47.                     for (int j = 1; 1 < genoms.Count;j++)
  48.                     {
  49.                         if (gen.EndsWith(genoms[j].Substring(0, 3)))
  50.                         {
  51.                             newgen = string.Concat(gen, genoms[j].Substring(3));
  52.                             gens.RemoveAt(j-1);
  53.  
  54.                             return ConcatRecursive(newgen, gens);
  55.                         }
  56.                         else
  57.                         {
  58.                             if (gen.EndsWith(genoms[j].Substring(0, 2)))
  59.                             {
  60.                                 newgen = string.Concat(gen, genoms[j].Substring(2));
  61.                                 gens.RemoveAt(j-1);
  62.  
  63.                                 return ConcatRecursive(newgen, gens);
  64.                             }
  65.                             else
  66.                             {
  67.                                 if (gen.EndsWith(genoms[j].Substring(0, 1)))
  68.                                 {
  69.                                     newgen = string.Concat(gen, genoms[j].Substring(1));
  70.                                     gens.RemoveAt(j-1);
  71.  
  72.                                     return ConcatRecursive(newgen, gens);
  73.                                 }
  74.  
  75.                             }
  76.                         }
  77.  
  78.                     }
  79.                
  80.                
  81.                
  82.             }return "Не вышло";
  83.             //    public List<string> geni = new List<string>();
  84.             //    //public Genome(List<string> coll) { geni = coll; }
  85.  
  86.             // public void perebor_elementov (List<string> geni)
  87.             //{
  88.             //    for (int i = 0; i < geni.Count; i++)
  89.             //    { Assembly(geni[i],geni); }
  90.             //}
  91.             //    public string Assembly (string gen ,List<string> geni )
  92.             //    {
  93.             //        //string result = string.Empty;
  94.  
  95.             //        //Здесь сравнение элемента с другими и соединение
  96.             //        for (int j = 0; 0 < geni.Count;j++)
  97.             //        {
  98.             //            if (gen.EndsWith(geni[j].Substring(1)))
  99.             //            {
  100.             //                gen = string.Concat(gen, geni[j].Substring(1));
  101.             //                geni.RemoveAt(j);
  102.             //            }
  103.             //            else
  104.             //            {
  105.             //                if (gen.EndsWith(geni[j].Substring(2)))
  106.             //                {
  107.             //                    gen = string.Concat(gen, geni[j].Substring(2));
  108.             //                    geni.RemoveAt(j);
  109.             //                }
  110.             //                else
  111.             //                {
  112.             //                    if (gen.EndsWith(geni[j].Substring(1)))
  113.             //                    {
  114.             //                        gen = string.Concat(gen, geni[j].Substring(1));
  115.             //                        geni.RemoveAt(j);
  116.             //                    }
  117.             //                    else { result = "не подошел"; return result; }
  118.             //                }
  119.             //            }
  120.  
  121.  
  122.             //        }
  123.             //        return gen;
  124.  
  125.             //    }
  126.  
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement