Advertisement
akass

Genomev3

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