Exemple #1
0
        public static void findLongestArithmeticProgression(int[] arr)
        {
            int length = arr.Length;
            System.Array.Sort(arr);
            int MaxD = (arr[length - 1] - arr[0]) / 3;
            System.Collections.Generic.SortedSet<int> ss = new System.Collections.Generic.SortedSet<int>(arr);
            for (int i = 0; i < length; i++)
            {
                int start = arr[i], count = 1;

                for (int j = i + 1; j < length; j++)
                {
                    int d = arr[j] - arr[i];
                    if (d > MaxD)
                    {
                        break;
                    }
                    while (ss.Contains(start + count * d))
                    {
                        ++count;
                    }
                    if (count >= MaxLength)
                    {
                        //print
                        for (int k = 0; k < count; k++)
                        {
                            System.Console.Write(start + k * d +" ");
                        }
                        System.Console.WriteLine();
                    }
                }
            }
        }
Exemple #2
0
        public static void findLongestArithmeticProgression(int[] arr)
        {
            int length = arr.Length;

            System.Array.Sort(arr);
            int MaxD = (arr[length - 1] - arr[0]) / 3;

            System.Collections.Generic.SortedSet <int> ss = new System.Collections.Generic.SortedSet <int>(arr);
            for (int i = 0; i < length; i++)
            {
                int start = arr[i], count = 1;

                for (int j = i + 1; j < length; j++)
                {
                    int d = arr[j] - arr[i];
                    if (d > MaxD)
                    {
                        break;
                    }
                    while (ss.Contains(start + count * d))
                    {
                        ++count;
                    }
                    if (count >= MaxLength)
                    {
                        //print
                        for (int k = 0; k < count; k++)
                        {
                            System.Console.Write(start + k * d + " ");
                        }
                        System.Console.WriteLine();
                    }
                }
            }
        }
Exemple #3
0
        public virtual string GetNewValue(Net.Vpc.Upa.Field field) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Entity entity = field.GetEntity();
            string             idName = field.GetName();
            string             goodId = null;

            for (int i = 0; i < asynchNbrTry; i++)
            {
                System.Collections.Generic.SortedSet <string> requestedIds = new System.Collections.Generic.SortedSet <string>();
                Net.Vpc.Upa.Expressions.InCollection          idsSet       = new Net.Vpc.Upa.Expressions.InCollection(new Net.Vpc.Upa.Expressions.Var(idName));
                for (int j = 0; j < synchNbrTry; j++)
                {
                    string id = (string)GenerateValue(field);
                    idsSet.Add(new Net.Vpc.Upa.Expressions.Literal(id));
                    requestedIds.Add(id);
                }
                System.Collections.Generic.IList <Net.Vpc.Upa.Record> recordList = entity.CreateQuery((new Net.Vpc.Upa.Expressions.Select()).From(entity.GetName()).Field(new Net.Vpc.Upa.Expressions.Var(idName)).Where(idsSet)).GetRecordList();
                System.Collections.Generic.SortedSet <string>         foundIds   = new System.Collections.Generic.SortedSet <string>();
                foreach (Net.Vpc.Upa.Record record in recordList)
                {
                    foundIds.Add(record.GetString());
                }
                Net.Vpc.Upa.Impl.FwkConvertUtils.SetRemoveRange(requestedIds, foundIds);
                if ((requestedIds.Count == 0))
                {
                    continue;
                }
                goodId = Net.Vpc.Upa.Impl.FwkConvertUtils.CollectionSetFirst <string>(requestedIds);
                break;
            }
            return(goodId);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            //System.Collections.ObjectModel.ObservableCollection<Member> members = new System.Collections.ObjectModel.ObservableCollection<Member>();
            //members.CollectionChanged += Members_CollectionChanged;
            //members.Add(new Member
            //{
            //    Id = 1,
            //    Fname = "Payam",
            //    Lname = "Boroumand"
            //});

            //System.Collections.Stack memberStack = new System.Collections.Stack();
            //memberStack.Push(new Member{ Id = 1, Fname = "Payam", Lname= "Boroumand"});
            //memberStack.Push(new Member{ Id = 2, Fname = "Mehrdad", Lname= "ALiMohammadi"});

            //object firstElement = memberStack.Pop();
            //Console.WriteLine(((Member)firstElement).ToString());

            //memberStack.Push(new Member{ Id = 1, Fname = "Milad", Lname= "Karimi"});

            //firstElement = memberStack.Pop();
            //Console.WriteLine(((Member)firstElement).ToString());


            //System.Collections.Queue membersQueue = new System.Collections.Queue();
            //membersQueue.Enqueue(new Member{ Id = 1, Fname = "Payam", Lname= "Boroumand"});
            //membersQueue.Enqueue(new Member{ Id = 1, Fname = "Mehrdad", Lname= "ALi Mohammadi"});

            //object firstElement = membersQueue.Dequeue();
            //Console.WriteLine(((Member)firstElement).ToString());
            //firstElement = membersQueue.Dequeue();
            //Console.WriteLine(((Member)firstElement).ToString());

            PrintMenu();

            System.Collections.Generic.SortedSet <Member> sortedMembersList = new System.Collections.Generic.SortedSet <Member>();
            sortedMembersList.Add(new Member {
                Id = 3, Fname = "Mehrdad", Lname = "ALi Mohammadi"
            });
            sortedMembersList.Add(new Member {
                Id = 2, Fname = "Alireza", Lname = "Boroumand"
            });
            sortedMembersList.Add(new Member {
                Id = 1, Fname = "Payam", Lname = "Boroumand"
            });
            sortedMembersList.Add(new Member {
                Id = 5, Fname = "Milad", Lname = "Karimi"
            });
            sortedMembersList.Add(new Member {
                Id = 4, Fname = "Amir", Lname = "Mohammadi"
            });

            foreach (var member in sortedMembersList)
            {
                Console.WriteLine(member.ToString());
            }

            Main(null);
        }
Exemple #5
0
 /// <summary>
 /// Muestra los Valores de un SortedSet generio de tipo Class Punto
 /// </summary>
 /// <param name="StPuntos">Nombre de la Instacia de la Class Punto</param>
 /// <param name="salto">Tipo de Salto deciado</param>
 public void Show
     (System.Collections.Generic.SortedSet <Punto> StPuntos, int salto = 1)
 {
     foreach (Punto p in StPuntos)
     {
         System.Console.Write("->{0}\n", p);
     }
     LineasEsp.Salto(salto);
 }
Exemple #6
0
 /// <summary>
 /// Muestra la cantidad de elementos de un SortedSet
 /// </summary>
 /// <param name="StPuntos">La instacia a cuantifical</param>
 /// <returns>la Cantidad de elementos</returns>
 public static int Count
     (System.Collections.Generic.SortedSet <Punto> StPuntos)
 {
     foreach (Punto p in StPuntos)
     {
         System.Console.Write("->{0}", StPuntos);
     }
     return(StPuntos.Count);
 }
Exemple #7
0
        /** チェック。
         */
        public static bool Check(System.Collections.Generic.SortedSet <int> a_from, System.Collections.Generic.SortedSet <int> a_to)
        {
            if (a_to == null)
            {
                UnityEngine.Debug.LogWarning("mismatch : null");
                return(false);
            }

            bool t_result = true;

            t_result &= Simple.Check_Enumerator("", a_from, a_to, (string a_a_label, int a_a_index, in int a_a_from, in int a_a_to) => {
                bool t_t_result = true;
                t_t_result     &= Simple.Check_Int(a_a_label, a_a_from, a_a_to);
                return(t_t_result);
            });

            return(t_result);
        }
Exemple #8
0
        /** 更新。
         */
        public static void Main(string a_label = nameof(Test_24))
        {
            UnityEngine.Debug.Log("----- " + a_label + " -----");

            try{
                System.Collections.Generic.SortedSet <int> t_item_from = new System.Collections.Generic.SortedSet <int>();
                {
                    t_item_from.Add(1);
                    t_item_from.Add(2);
                    t_item_from.Add(3);
                }

                //オブジェクト ==> JSONITEM。
                                #if (FEE_JSON)
                Fee.JsonItem.JsonItem t_jsonitem = Fee.JsonItem.Convert.ObjectToJsonItem <System.Collections.Generic.SortedSet <int> >(t_item_from);
                                #endif

                //JSONITEM ==> JSON文字列。
                                #if (FEE_JSON)
                string t_jsonstring = t_jsonitem.ConvertToJsonString();
                                #else
                string t_jsonstring = UnityEngine.JsonUtility.ToJson(t_item_from);
                                #endif

                //JSON文字列 ==> オブジェクト。
                                #if (FEE_JSON)
                System.Collections.Generic.SortedSet <int> t_item_to = Fee.JsonItem.Convert.JsonStringToObject <System.Collections.Generic.SortedSet <int> >(t_jsonstring);
                                #else
                System.Collections.Generic.SortedSet <int> t_item_to = UnityEngine.JsonUtility.FromJson <System.Collections.Generic.SortedSet <int> >(t_jsonstring);
                                #endif

                //ログ。
                UnityEngine.Debug.Log(a_label + " : " + t_jsonstring);

                //チェック。
                if (Check(t_item_from, t_item_to) == false)
                {
                    UnityEngine.Debug.LogError("mismatch");
                }
            }catch (System.Exception t_exception) {
                UnityEngine.Debug.LogError(a_label + " : exception : " + t_exception.Message);
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            var visits  = new System.Collections.Generic.SortedSet <EDJournal.SystemVisit>();
            var systems = new System.Collections.Generic.HashSet <string>();

            string journal_path = System.IO.Path.Combine(
                Environment.GetEnvironmentVariable("USERPROFILE"),
                "Saved Games",
                "Frontier Developments",
                "Elite Dangerous"
                );

            foreach (string journal_file in System.IO.Directory.EnumerateFiles(journal_path, "Journal.*.log"))
            {
                foreach (var visit in EDJournal.Consumer.ProcessFile(journal_file))
                {
                    visits.Add(visit);
                    systems.Add(visit.Name);
                }
            }

            double distance = 0;

            EDJournal.Position previous = null;

            foreach (var visit in visits)
            {
                if (previous != null)
                {
                    distance += visit.DistanceTo(previous);
                }
                previous = visit.Position;
            }

            Console.WriteLine("Found {0} visits to {1} distinct systems. Travelled {2} light years.",
                              visits.Count,
                              systems.Count,
                              distance.ToString("N2", CultureInfo.CreateSpecificCulture("en-UK"))
                              );
        }
 public virtual System.Collections.Generic.ICollection <Net.Vpc.Upa.Impl.Persistence.ValidationPass> GetValidationPasses()
 {
     System.Collections.Generic.SortedSet <Net.Vpc.Upa.Impl.Persistence.ValidationPass> ts = new System.Collections.Generic.SortedSet <Net.Vpc.Upa.Impl.Persistence.ValidationPass>();
     foreach (Net.Vpc.Upa.Impl.Persistence.ValidationPass[] o in (orderedPasses).Values)
     {
         for (int i = 0; i < 4; i++)
         {
             if (o[i] != null)
             {
                 ts.Add(o[i]);
             }
         }
     }
     return(ts);
 }
 // CONSTRUCTORS
 public PriorityQueue()
 {
     priorityQueue = new System.Collections.Generic.SortedSet <T>();
 }
 public PriorityQueue(System.Collections.Generic.IComparer <T> comparer)
 {
     priorityQueue = new System.Collections.Generic.SortedSet <T>(comparer);
 }
 // CONSTRUCTORS
 public Alphabet(string letters)
 {
     this.letter = new System.Collections.Generic.SortedSet <char>(letters);
 }