Example #1
0
    string GetCorrespondingTag(sequence state) {
        string tag = null;
        switch (state) {
            case sequence.first: {
                    tag = Keys.TAG_STATE_FIRST;
                    break;
                }
            case sequence.second:
                {
                    tag = Keys.TAG_STATE_SECOND;
                    break;
                }
            case sequence.third:
                {
                    tag = Keys.TAG_STATE_THIRD;
                    break;
                }
            case sequence.fourth:
                {
                    tag = Keys.TAG_STATE_FOURTH;
                    break;
                }

        }
        return tag;
    }
Example #2
0
    public static void Main()
    {
        Stopwatch sw = new Stopwatch();
        sequence calc= new sequence();
        sequence largest = new sequence();
        string numbers="7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450";

        sw.Start();
        for (int i=0;i<996;i++)
        {
        int a,b,c,d,e;
        a=Int32.Parse(numbers.Substring(i,1));
        b=Int32.Parse(numbers.Substring(i+1,1));
        c=Int32.Parse(numbers.Substring(i+2,1));
        d=Int32.Parse(numbers.Substring(i+3,1));
        e=Int32.Parse(numbers.Substring(i+4,1));
        calc.fill(a,b,c,d,e);
        //Console.WriteLine("{0} * {1} * {2} * {3} * {4}  = {5}",a,b,c,d,e,calc.prod);
        if (calc.prod > largest.prod)
        {
        largest.fill(a,b,c,d,e);
        }
        }
        sw.Stop();
        Console.WriteLine("Elapsed time {6} The largest product is {0} with factors {1} {2}  {3}  {4} {5}",
        largest.prod, largest.a,largest.b,largest.c,largest.d,largest.e,sw.Elapsed);
        return;
    }
Example #3
0
 public static void Modify(sequence Sequence)
 {
     ///<summary>
     ///Prend en parametre un quizz le modifie et affiche un message qui confirme la modification
     /// </summary>
     db.sequences.Attach(Sequence);
     db.Entry(Sequence).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
Example #4
0
        public static void Add(sequence Sequence)
        {
            ///<summary>
            ///Permet l'ajout d'un nouveau quizz
            /// </summary>

            db.sequences.Add(Sequence);
            db.SaveChanges();
        }
Example #5
0
        public static sequence Select(int id)
        {
            ///<summary>
            ///Permet d'avoir un seul quizz en fonction de son ID qui est unique
            /// </summary>
            /// <param name="id">ID du quizz</param>
            sequence seq = db.sequences.Find(id);

            return(seq);
        }
Example #6
0
        public static void Delete(sequence Sequence)
        {
            ///<summary>
            ///Permet la suppresion d'un quizz
            /// </summary>

            db.sequences.Attach(Sequence);
            db.sequences.Remove(Sequence);
            db.SaveChanges();
        }
Example #7
0
        public Task <IEnumerable <Unit> > GetUnits(jobProfile p, competency c, sequence s)
        {
            List <Task <IEnumerable <Unit> > > tasks = new List <Task <IEnumerable <Unit> > >();

            foreach (item i in s.item)
            {
                tasks.Add(GetUnits(p, c, i));
            }
            return(Task.WhenAll(tasks).ContinueWith((lists) => lists.Result.SelectMany(e => e)));
        }
Example #8
0
    // Start is called before the first frame update
    void Start()
    {
        audioSource = GetComponent <AudioSource>();



        readytogoin = false;
        s           = GameObject.Find("SequenceManager").GetComponent <sequence>();
        speed       = 1.4f;
        // Debug.Log(newdooropen);
    }
Example #9
0
File: Form1.cs Project: 18-th/Calc
        void GetSequences()
        {
            string temp;
            int    counter = 0;

            System.IO.StreamReader file = new System.IO.StreamReader("mutes.txt");
            while ((temp = file.ReadLine()) != null)
            {
                variants[counter] = new sequence(temp, counter);
                counter++;
            }
            file.Close();
        }
    public tasks getCurrentTask()
    {
        List <tasks> taskList = new List <tasks>();

        tasks openDoor = new OpenDoor();
        tasks bargeIn  = new BargeDoor();

        taskList.Add(openDoor);
        taskList.Add(bargeIn);

        sequence bargeClosedDoor = new sequence(taskList);

        return(bargeClosedDoor);
    }
Example #11
0
    void Start()
    {
        if (GameObject.Find("SequenceManager"))
        {
            s = GameObject.Find("SequenceManager").GetComponent <sequence>();
        }
        else
        {
            s         = gameObject.AddComponent <sequence>();
            s.enabled = false;
        }


        startVector = transform.position;
    }
Example #12
0
File: Form1.cs Project: 18-th/Calc
 int[,] GetPrioritiesMatrix(sequence currentSequence)
 {
     int[,] priorMat = new int[6, 6];
     for (int i = 0; i < transactons.Count; i++)
     {
         if ((currentSequence.firstMag.Contains <int>(transactons[i].first) && currentSequence.firstMag.Contains <int>(transactons[i].second)) ||
             (currentSequence.secondMag.Contains <int>(transactons[i].first) && currentSequence.secondMag.Contains <int>(transactons[i].second)))
         {
             priorMat[transactons[i].first - 1, transactons[i].second - 1] = 1;
         }
         else
         {
             priorMat[transactons[i].first - 1, transactons[i].second - 1] = 2;
         }
     }
     return(priorMat);
 }
Example #13
0
            internal SequenceInfo(sequence seq)
            {
                Name = seq.Name;
                var block = seq.Block;

                if (block != null)
                {
                    Authority     = block.Authority;
                    AuthorityHost = block.AuthorityHost;
                    Era           = block.Era;
                    Value         = block.StartCounterInclusive + (ulong)(block.BlockSize - block.__Remaining);
                    UTCTime       = block.ServerUTCTime;
                    BlockSize     = block.BlockSize;
                    Remaining     = block.__Remaining;
                }
                NextBlock = seq.NextBlock != null;
            }
Example #14
0
        private void button_Valider_Click(object sender, RoutedEventArgs e)
        {
            QS.reponse__sequence = new List <reponse__sequence>();
            foreach (var item in listView_Reponse.Items)
            {
                QS.reponse__sequence.Add(item as reponse__sequence);
            }
            foreach (var item in listView_Question.Items)
            {
                (App.Current as App).listequestion.Add(QS);
            }
            List <question__sequence> questseq = new List <question__sequence>();

            questseq.Add(QS);
            sequence newseq = new sequence {
                Intitule = textBox.Text, question__sequence = questseq
            };

            (App.Current as App).newsequence = newseq;
            (App.Current as App).listeseq.Add(newseq);
        }
Example #15
0
        private const double MIN_TIME_SLICE_SEC       = 0.01d; //10ms

        private GDIDBlock allocateBlock(sequence seq, int blockSize, ulong?vicinity = GDID.COUNTER_MAX)
        {
            m_BlockWasAllocated = true;

            if (blockSize <= 0)//calculate the most appropriate
            {
                var now = DateTime.UtcNow;
                var sinceLastAllocationSec = (now - seq.LastAllocationUTC).TotalSeconds;
                if (sinceLastAllocationSec < MIN_TIME_SLICE_SEC)
                {
                    sinceLastAllocationSec = MIN_TIME_SLICE_SEC;
                }
                seq.LastAllocationUTC = now;

                seq.avgSinceLastAlloc1 = seq.avgSinceLastAlloc2;
                seq.avgSinceLastAlloc2 = seq.avgSinceLastAlloc3;
                seq.avgSinceLastAlloc3 = sinceLastAllocationSec;

                var avg = (seq.avgSinceLastAlloc1 +
                           seq.avgSinceLastAlloc2 +
                           seq.avgSinceLastAlloc3) / 3d;

                if (avg == 0)
                {
                    avg = MIN_TIME_SLICE_SEC;
                }

                blockSize = MIN_BLOCK_SZ + (int)((NORM_AUTH_CALL_EVERY_SEC * NORM_IDS_PER_SEC) / avg);
            }
////Console.WriteLine("|--------------------> Block size is: "+blockSize);
            if (m_TestingAuthorityNode.IsNullOrWhiteSpace())
            {
                return(allocateBlockInSystem(seq.Scope.Name, seq.Name, blockSize, vicinity));
            }
            else
            {
                return(allocateBlockInTesting(seq.Scope.Name, seq.Name, blockSize, vicinity));
            }
        }
Example #16
0
 public sequence(sequence other)
 {
     str   = other.str;
     count = other.count;
 }
Example #17
0
    private void GenStmt(stmt stmt)
    {
        if (stmt is sequence)
        {
            sequence seq = (sequence)stmt;
            this.GenStmt(seq.first);
            this.GenStmt(seq.second);
        }

        else if (stmt is DeclareS)
        {
            // declare a local
            counting++;
            DeclareS declare = (DeclareS)stmt;
            this.symbolTable[declare.Ident] = il.DeclareLocal(TypeOfExpr(declare.Expr));

            // set the initial value
            assign assign = new assign();
            assign.Ident = declare.Ident;
            assign.Expr  = declare.Expr;
            this.GenStmt(assign);
        }

        else if (stmt is assign)
        {
            counting++;
            assign assign = (assign)stmt;
            counters = 0;
            this.GenExpr(assign.Expr, this.TypeOfExpr(assign.Expr));

            this.Store(assign.Ident, this.TypeOfExpr(assign.Expr));
        }
        else if (stmt is display)
        {
            // the "display" statement is an alias for System.Console.WriteLine.
            // it uses the string case
            counting++;
            this.GenExpr(((display)stmt).Expr, typeof(string));

            this.il.Emit(Emit.OpCodes.Call, typeof(System.Console).GetMethod("WriteLine", new System.Type[] { typeof(string) }));
        }
        else if (stmt is Just_Declare)
        {
            counting++;
            Just_Declare declare = (Just_Declare)stmt;
            this.symbolTable[declare.Ident] = this.il.DeclareLocal(typeof(int));


            //this.Store(declare.Ident, typeof(int));
        }

        else if (stmt is acquire)
        {
            counting++;
            this.il.Emit(Emit.OpCodes.Call, typeof(System.Console).GetMethod("ReadLine", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, new System.Type[] { }, null));
            this.il.Emit(Emit.OpCodes.Call, typeof(int).GetMethod("Parse", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, new System.Type[] { typeof(string) }, null));
            this.Store(((acquire)stmt).Ident, typeof(int)); // stores the identifier in stack
        }
        else
        {
            throw new System.Exception("don't know how to gen a " + stmt.GetType().Name);
        }
    }
Example #18
0
        private stmt ParseStmt()
        {
            stmt result;

            #region newline
            linecount();
            #endregion

            if (index < tokens.Count - 1)
            {
                #region DISPLAY
                if (index != tokens.Count - 1 && tokens[index].ToString().Equals("display"))
                {
                    //   linecount();
                    // ////MessageBox.Show("i am in display");
                    display Display = new display();
                    index++;
                    linecount();
                    Display.Expr = ParsExpr("blah");
                    if (Display.Expr is StringLiteral || Display.Expr is Variable)
                    {
                        if (Display.Expr is Variable)
                        {
                            //MessageBox.Show(tokens[index - 1].ToString());
                            if (!identifier.identity.Contains(tokens[index - 1].ToString()))
                            {
                                adderror("undeclared identifier");
                                linecount();
                                // index++;
                            }
                            else if (identifier.assignment[identifier.identity.IndexOf(tokens[index - 1].ToString())] == false)
                            {
                                adderror(tokens[index - 1].ToString() + " : unassigned");
                                linecount();
                                // index++;
                            }
                        }
                        if (!tokens[index].Equals(scanner.opend.endline))
                        {
                            adderror("Expected Endline Character");
                            index--;
                        }
                        //else
                        //{
                        index++;
                        linecount();
                        //}
                        result = Display;
                        //  ////MessageBox.Show(tokens[index].ToString());
                    }
                    else
                    {
                        result = null;
                        adderror("expected Variable or Display Statement");
                        index++;
                        linecount();

                        if (!tokens[index].Equals(scanner.opend.endline))
                        {
                            adderror("Expected Endline Character");
                            index--;
                            //index++;
                        }
                    }
                    counts++;
                }
                #endregion

                #region For vs and cs and register and int
                else if (tokens[index].ToString().Equals("vs") || tokens[index].ToString().Equals("cs") || tokens[index].ToString().Equals("register") || tokens[index].ToString().Equals("int") || tokens[index].ToString().Equals("string"))
                {
                    string dose = tokens[index].ToString();
                    index++;
                    linecount();

                    DeclareS sources = new DeclareS();
                    if (!(index < tokens.Count && tokens[index] is string))
                    {
                        adderror("expected variable name");
                        index++;
                        linecount();
                    }
                    else if (identifier.identity.Contains(tokens[index].ToString()))
                    {
                        adderror(tokens[index].ToString() + " : redefinition");
                        index++;
                        linecount();
                    }
                    else
                    {
                        sources.Ident = tokens[index].ToString();
                    }
                    index++;
                    linecount();

                    if ((index == tokens.Count) || (!(tokens[index].Equals((object)scanner.opend.equal)) && !(tokens[index].Equals(scanner.opend.endline))))
                    {
                        //////MessageBox.Show(tokens[index].ToString());
                        adderror("Expected #/=");
                        // index++;
                    }
                    #region var identifier
                    if (tokens[index].Equals((object)scanner.opend.endline))
                    {
                        Just_Declare classy = new Just_Declare();
                        classy.Ident = tokens[index - 1].ToString();
                        if (identifier.identity.Contains(tokens[index - 1].ToString()))
                        {
                            adderror(tokens[index - 1].ToString() + " : redefinition");
                            index++;
                            linecount();
                        }
                        identifier.identity.Add(classy.Ident.ToString());

                        identifier.assignment.Add(false);

                        result = classy;
                        index++;
                        linecount();
                    }
                    #endregion

                    else
                    {
                        index++;
                        linecount();

                        sources.Expr = ParsExpr("blah");
                        if (dose == "string")
                        {
                            //MessageBox.Show("hello world");
                            if (!(sources.Expr is StringLiteral))
                            {
                                adderror("expected string type");
                                index++;
                                sources = null;
                            }
                            else
                            {
                                //MessageBox.Show("lala");
                                identifier.identity.Add(sources.Ident.ToString());
                                identifier.assignment.Add(true);
                                MessageBox.Show("haha");
                                //index++;
                                MessageBox.Show(tokens[index].ToString());
                            }
                            if (!tokens[index].Equals(scanner.opend.endline))
                            {
                                //////MessageBox.Show(tokens[index].ToString());
                                adderror("Exepected Endline Character");
                                index--;
                            }
                            index++;
                            linecount();
                            result = sources;
                        }
                        else
                        {
                            if (sources.Expr is StringLiteral)
                            {
                                adderror("expected variable or integer after '=' ");
                                //index++;
                            }
                            else if (sources.Expr is Variable)
                            {
                                if (!identifier.identity.Contains(tokens[index - 1].ToString()))
                                {
                                    //////MessageBox.Show();
                                    adderror(tokens[index - 1].ToString() + " undeclared identifier");
                                    //  index++;
                                }

                                else if (identifier.assignment[identifier.identity.IndexOf(tokens[index - 1].ToString())] == false)
                                {
                                    adderror(tokens[index - 1].ToString() + " : unassigned");
                                    // index++;
                                }
                            }

                            identifier.identity.Add(sources.Ident.ToString());
                            identifier.assignment.Add(true);
                            if (!tokens[index].Equals(scanner.opend.endline))
                            {
                                //////MessageBox.Show(tokens[index].ToString());
                                adderror("Exepected Endline Character");
                                index--;
                            }
                            index++;
                            linecount();

                            result = sources;
                        }
                    }
                    counts++;
                }
                #endregion

                #region for Acquire
                else if (tokens[index].ToString().Equals("acquire"))
                {
                    index++;
                    linecount();
                    acquire acquire = new acquire();
                    if (index < tokens.Count && tokens[index] is string)
                    {
                        acquire.Ident = tokens[index].ToString();
                        ////MessageBox.Show(tokens[index].ToString());
                        if (!identifier.identity.Contains(acquire.Ident.ToString()))
                        {
                            adderror("Expected declared Identifier");
                            //index++;
                        }

                        result = acquire;
                        identifier.assignment[identifier.identity.IndexOf(tokens[index].ToString())] = true;
                        index++;
                        if (!tokens[index].Equals(scanner.opend.endline))
                        {
                            adderror("Expected Endline Character");
                            index--;
                            //index++;
                        }

                        linecount();
                    }
                    else
                    {
                        result = null;
                        adderror("Expected Identifier");
                    }
                    index++;
                    linecount();
                    counts++;
                }
                #endregion

                #region If and If Else
                else if (tokens[index].ToString().Equals("if"))
                {
                    bool ife = false;
                    index++;
                    linecount();
                    ifS    ifs    = new ifS();
                    ifElse ifelse = new ifElse();
                    ifs.Cond = ParseCond();
                    if (ifs.Cond is IntLiteral || ifs.Cond is Something || ifs.Cond is Variable)
                    {
                        adderror("Expected Conditional Statement");
                        //index++;
                    }
                    //index++;
                    if (index == tokens.Count || !(tokens[index].ToString().Equals("do")))
                    {
                        adderror("Expected do");
                        index--;
                    }
                    index++;
                    linecount();
                    ifs.Body = ParseStmt();
                    // ////MessageBox.Show(tokens[index].ToString() + " b4 else");
                    //index++;

                    #region ifelse
                    if (tokens[index].ToString().Equals("else"))
                    {
                        index++;
                        linecount();

                        ifelse.ifEverything = ifs;
                        if (index == tokens.Count || !(tokens[index].ToString().Equals("do")))
                        {
                            adderror("Expected do");
                            index--;
                        }
                        index++;
                        linecount();
                        ifelse.bodyelse = ParseStmt();
                        //index++;
                        if (index == tokens.Count || !(tokens[index].ToString().Equals("endelse")))
                        {
                            adderror("unterminated 'if else' body");
                            //index++;
                        }

                        ife = true;
                    }
                    #endregion
                    else if (index == tokens.Count || !(tokens[index].ToString().Equals("endif")))
                    {
                        result = null;
                        adderror("unterminated 'if' body");
                        index++;
                    }
                    if (!ife)
                    {
                        index++;
                        linecount();
                        if (index == tokens.Count || !(tokens[index].Equals((object)scanner.opend.endline)))
                        {
                            result = null;
                            adderror("Expected endline character #");
                            index--;
                        }
                        else
                        {
                            result = ifs;
                        }
                    }
                    else
                    {
                        index++;
                        linecount();
                        if (index == tokens.Count || !(tokens[index].Equals((object)scanner.opend.endline)))
                        {
                            result = null;
                            adderror("Expected endline character #");
                            index--;
                        }
                        else
                        {
                            result = ifelse;
                        }
                    }
                    index++;
                    linecount();
                    counts++;
                }
                #endregion

                #region While loop
                else if (tokens[index].ToString().Equals("while"))
                {
                    index++;
                    linecount();
                    whileLoop whilel = new whileLoop();
                    whilel.cond = ParseCond();
                    ////MessageBox.Show(tokens[index].ToString());
                    //index++;

                    if (index == tokens.Count || !(tokens[index].ToString().Equals("do")))
                    {
                        ////MessageBox.Show(tokens[index].ToString());
                        adderror("Expected do");
                        index--;
                    }
                    index++;
                    linecount();
                    //////MessageBox.Show(tokens[index].ToString());
                    whilel.body = ParseStmt();
                    ////MessageBox.Show(tokens[index].ToString());
                    //index++;
                    if (index == tokens.Count || !(tokens[index].ToString().Equals("endwhile")))
                    {
                        adderror("unterminated 'while' loop body");
                    }
                    index++;
                    linecount();
                    if (index == tokens.Count || !(tokens[index].Equals((object)scanner.opend.endline)))
                    {
                        adderror("Expected endline #");
                        index--;
                    }
                    result = whilel;
                    index++;
                    linecount();
                    counts++;
                    ////MessageBox.Show(tokens[index].ToString()+" in while");
                }
                #endregion

                #region Assignment
                else if (tokens[index] is string)
                {
                    assign assign = new assign();
                    if (!identifier.identity.Contains(tokens[index].ToString()))
                    {
                        adderror(tokens[index] + " undeclared identifier");
                    }

                    assign.Ident = tokens[index].ToString();
                    index++;
                    linecount();



                    if (tokens.Count == index || !(tokens[index].Equals((object)scanner.opend.equal)))
                    {
                        adderror("expected '='");
                    }
                    index++;
                    linecount();
                    assign.Expr = ParsExpr("blah");
                    if (assign.Expr is StringLiteral)
                    {
                        adderror("Expected integer/variable");
                    }
                    else if (assign.Expr is Variable)
                    {
                        if (!identifier.identity.Contains(tokens[index - 1].ToString()))
                        {
                            adderror(tokens[index - 1] + " : undeclared identifier");
                        }

                        else if (identifier.assignment[identifier.identity.IndexOf(tokens[index - 1].ToString())] == false)
                        {
                            adderror(tokens[index - 1].ToString() + " : unassigned");
                        }
                    }

                    result = assign;
                    if (index < tokens.Count)
                    {
                        if (tokens[index].ToString().Equals("#"))
                        {
                            adderror("Expected EndLine Character");
                            index--;
                        }
                    }
                    //index++;
                    counts++;
                }
                #endregion

                #region Invalid Statement

                else
                {
                    linecount();
                    adderror("parse error at token " + index + ": " + tokens[index]);
                    result = ParseStmt();
                }
                #endregion

                #region statement list

                //MessageBox.Show("b4 stmt_list");
                if ((index < tokens.Count) && (!(tokens[index].ToString().Equals("end"))))
                {
                    // index++;
                    if (((!tokens[index].ToString().Equals("endwhile") && !tokens[index].ToString().Equals("endif"))) && (!tokens[index].ToString().Equals("endelse") && !tokens[index].ToString().Equals("else")))
                    {
                        //MessageBox.Show("i m in stmt_list");
                        linecount();
                        //MessageBox.Show(tokens[index ].ToString());


                        sequence seq = new sequence();

                        seq.first  = result;
                        seq.second = ParseStmt();
                        result     = seq;
                    }
                }


                //}

                #endregion


                return(result);
            }
            else
            {
                return(null);
            }
        }
Example #19
0
 AssertSetEqual(sequence, expectedSequence, EqualityComparer <T> .Default.Equals, out remainder);
Example #20
0
    public void UpdateSequence(sequence newState) {
        Debug.Log("UpdateSequence, sequenceCorrect.lenght is: " + sequenceCorrect.Length);
        if (mHowManyChanges < (sequenceCorrect.Length - 1))
        {
            mHowManyChanges++;
        }

        if (newState.Equals(sequenceCorrect[mHowManyChanges]))
        { //the sequence is correct
            mCurrentSequence.Add(newState);
            MainPlayer.objectPlayer[mHowManyChanges - 1].SetActive(false);
            currentState = newState;
            isCorrect = true;
            Debug.Log("UpdateSequence new state is the state correct");
        }
        else {
            // The sequence is incorrect
            currentState = newState;
            string tag = GetCorrespondingTag(newState);
            if (tag == Keys.TAG_STATE_SECOND || tag == Keys.TAG_STATE_FOURTH) //Scene with platform
            {
                Debug.Log("UpdateSequence the sequence is incorrect");
                GameObject gameObject = GameObject.FindGameObjectWithTag(tag);
                HandlePlatform hp = gameObject.GetComponent<HandlePlatform>();
                hp.DestroyPlatformOnCollision(true);
                hp.spawnObject(false);
                isCorrect = false;
            }
            else { //Other scene?
                Debug.Log("Forse dobbiamo attivare altri eventi");
            }
        }
    }
Example #21
0
File: Form1.cs Project: 18-th/Calc
        void SetOutputData(int[,] infoAmountMatrix, sequence top)
        {
            int[,] infoMatrix = new int[6, 6];
            for (int i = 0; i < infoAmountMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < infoAmountMatrix.GetLength(1); j++)
                {
                    infoMatrix[i, j] = infoAmountMatrix[i, j];
                }
            }
            sequence c = top;

            //Переставляем матрицу количества передач
            for (int i = 0; i < infoAmountMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < infoAmountMatrix.GetLength(1); j++)
                {
                    infoMatrix[i, j] = infoAmountMatrix[i, j];
                }
            }
            //
            int[,] priorityMatrix = GetPrioritiesMatrix(c);
            int firstMagStationsToParallel  = 0;
            int secondMagStationsToParallel = 0;

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    if (priorityMatrix[i, j] == 1 && c.firstMag.Contains(i + 1))
                    {
                        firstMagStationsToParallel++;
                    }
                    else if (priorityMatrix[i, j] == 1 && c.secondMag.Contains(i + 1))
                    {
                        secondMagStationsToParallel++;
                    }
                }
            }
            bool sended            = false;
            pair firstMagMaxInd    = new pair(0, 0);
            pair secondMagMaxInd   = new pair(0, 0);
            int  firstMagMaxTrans  = 0;
            int  secondMagMaxTrans = 0;
            bool firstFrozen       = false;
            bool secondFrozen      = false;
            //Список для теста, составлять для каждой ситуации - слишком жирно по производительности
            //
            int checker = 0;
            int time    = 0;

            while (!sended)
            {
                if (!firstFrozen)
                {
                    firstMagMaxTrans = 0;
                }
                if (!secondFrozen)
                {
                    secondMagMaxTrans = 0;
                }
                checker = 0;
                if (secondMagStationsToParallel == 0 || firstMagStationsToParallel == 0)
                {
                    break;
                }
                for (int i = 0; i < 6; i++) //Проходим по массиву в поисках подходящих для передачи элементов
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (priorityMatrix[i, j] == 1 && infoMatrix[i, j] != 0)
                        {
                            if (c.firstMag.Contains(i + 1) && !firstFrozen)
                            {
                                if (infoMatrix[i, j] > firstMagMaxTrans)
                                {
                                    firstMagMaxTrans      = infoMatrix[i, j];
                                    firstMagMaxInd.first  = i;
                                    firstMagMaxInd.second = j;
                                    checker++;
                                }
                            }
                            else if (c.secondMag.Contains(i + 1) && !secondFrozen)
                            {
                                if (infoMatrix[i, j] > secondMagMaxTrans)
                                {
                                    secondMagMaxTrans      = infoMatrix[i, j];
                                    secondMagMaxInd.first  = i;
                                    secondMagMaxInd.second = j;
                                    checker++;
                                }
                            }
                        }
                    }
                }
                if (secondMagMaxTrans > firstMagMaxTrans && infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second] > 0)
                {
                    infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] -= firstMagMaxTrans;
                    infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second]   -= firstMagMaxTrans;
                    secondMagMaxTrans -= firstMagMaxTrans;
                    firstMagStationsToParallel--;
                    time += firstMagMaxTrans;
                    secondMagistralOut.Add(new magistralPiece(secondMagMaxInd.first + 1, secondMagMaxInd.second + 1, firstMagMaxTrans));
                    firstMagistralOut.Add(new magistralPiece(firstMagMaxInd.first + 1, firstMagMaxInd.second + 1, firstMagMaxTrans));
                    secondFrozen = true;
                    firstFrozen  = false;
                }
                else if (secondMagMaxTrans < firstMagMaxTrans && infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] > 0)
                {
                    infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second]   -= secondMagMaxTrans;
                    infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] -= secondMagMaxTrans;
                    firstMagMaxTrans -= secondMagMaxTrans;
                    secondMagStationsToParallel--;
                    time += secondMagMaxTrans;
                    firstMagistralOut.Add(new magistralPiece(firstMagMaxInd.first + 1, firstMagMaxInd.second + 1, secondMagMaxTrans));
                    secondMagistralOut.Add(new magistralPiece(secondMagMaxInd.first + 1, secondMagMaxInd.second + 1, secondMagMaxTrans));
                    secondFrozen = false;
                    firstFrozen  = true;
                }
                else if (secondMagMaxTrans == firstMagMaxTrans && infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] > 0)
                {
                    infoMatrix[firstMagMaxInd.first, firstMagMaxInd.second]   -= firstMagMaxTrans;
                    infoMatrix[secondMagMaxInd.first, secondMagMaxInd.second] -= secondMagMaxTrans;
                    secondMagStationsToParallel--;
                    firstMagStationsToParallel--;
                    time += secondMagMaxTrans;
                    firstMagistralOut.Add(new magistralPiece(firstMagMaxInd.first + 1, firstMagMaxInd.second + 1, firstMagMaxTrans));
                    secondMagistralOut.Add(new magistralPiece(secondMagMaxInd.first + 1, secondMagMaxInd.second + 1, secondMagMaxTrans));
                    secondFrozen = false;
                    firstFrozen  = false;
                }
                if (checker == 0)
                {
                    sended = true;
                }
            }
            //Добавляем оставшиеся передачи по одной магистрали,а потом полные передачи
            bool over = false;

            while (!over)
            {
                checker = 0;
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (priorityMatrix[i, j] == 1 && infoMatrix[i, j] != 0)
                        {
                            if (c.firstMag.Contains(i + 1))
                            {
                                firstMagistralOut.Add(new magistralPiece(i + 1, j + 1, infoMatrix[i, j]));
                                secondMagistralOut.Add(new magistralPiece(0, 0, infoMatrix[i, j]));
                                infoMatrix[i, j] = 0;
                                checker++;
                            }
                            else if (c.secondMag.Contains(i + 1))
                            {
                                secondMagistralOut.Add(new magistralPiece(i + 1, j + 1, infoMatrix[i, j]));
                                firstMagistralOut.Add(new magistralPiece(0, 0, infoMatrix[i, j]));
                                infoMatrix[i, j] = 0;
                                checker++;
                            }
                        }
                    }
                }
                if (checker == 0)
                {
                    over = true;
                }
            }
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    if (priorityMatrix[i, j] == 2 && infoMatrix[i, j] != 0)
                    {
                        firstMagistralOut.Add(new magistralPiece(i + 1, j + 1, infoMatrix[i, j]));
                        secondMagistralOut.Add(new magistralPiece(i + 1, j + 1, infoMatrix[i, j]));
                        infoMatrix[i, j] = 0;
                        checker++;
                    }
                }
            }
            SetCurrentTime();
            pictureBox1.Invalidate();
        }
Example #22
0
 public Status postionsequence(sequence Sequence)
 {
     return sequencehelper.postionsequence(sequence)
 }
Example #23
0
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());

        if (n > 0)
        {
            List <sequence> arr = new List <sequence>();

            sequence last = new sequence(), temp = new sequence();
            for (int i = 0; i < n; ++i)
            {
                temp.str = Console.ReadLine();

                if (last.str == temp.str)
                {
                    ++last.count;
                }
                else
                {
                    if (last.str == "")
                    {
                        last.str = temp.str;
                    }
                    else
                    {
                        arr.Add(new sequence(last));
                        last.str = temp.str;
                    }
                    last.count = 1;
                }

                temp.count = 1;
            }
            if (last.str == temp.str)
            {
                if (last.str != "")
                {
                    arr.Add(new sequence(last));
                }
                else
                {
                    arr.Add(new sequence(temp));
                }
            }

            int index = 0, maxCount = 0;
            for (int i = 0; i < arr.Count; ++i)
            {
                if (arr[i].count > maxCount)
                {
                    maxCount = arr[i].count;
                    index    = i;
                }
            }

            arr[index].Print();
        }
        else
        {
            Console.WriteLine("invalid n");
        }
    }