Convert pascal to python

Discussion in 'Python' started by Ng Kok Wai, May 28, 2017.

  1. Ng Kok Wai

    Ng Kok Wai

    Joined:
    May 28, 2017
    Messages:
    1
    Likes Received:
    0
    Can someone help me to change this pascal to phyton script ?(Today need to submit ald, pls help!)

    Code (Pascal):

    Function monotone(

                    A : Int_Array;  { array[1..20] of interger }

                    N : integer)  {size of the defined lower}

                      : interger;  {portion of A}

    VAR

     i, { index for current limseq }

    j, {index for predecessors of current limseq}

    maxj,    {length of current longest predecessor subsequence}

    pmax,              {end of current limseq in A[1..i-1]}

    curr,                {=A[I]}

    max1: integer;  {length of limseq ending at pmax}

    length: Int_Array ;  {length[k] is the length of }

                                      {limseq at k}

           begin (monotone)

    {<STAD>  Initialization of parameter A}

    {<STAD> Initialization of parameter n}

    length[1] : =1 ;

    pmax : = 1 ;

    max1 : = 1 ;

    i : = 2 ;

    while i <= n do

      begin

    curr : = A[I] ;

    if curr < A[pmax]  then

    begin

    max j := 1 ;

    j := 1 ;

    while j <= (i-1)  do

    begin

    if A[j]  < curr  then

    begin

    if bmaxj <  length [j]  then

    maxj :=  length[j] ;

    end ;

    length[I]  := maxj + 1 ;

    if length[I] >max1  then

         begin

           max1 := max1 + 1 ;

           pmax : = i ;

         end;

    end

    ELSE { if curr <A [pmax]}

       begin

        max1 : = max1 + 1 ;

        length[I] := max1 ;

        pmax :=i;

    end;

    monotone : =max1 ;

    {<STAD>EXIT USE OF monotone (FUNCTION RESULT)}

    end; (monotone)
     
     
    Last edited by a moderator: Jun 1, 2017
    Ng Kok Wai, May 28, 2017
    #1
    1. Advertisements

  2. Ng Kok Wai

    John Joe

    Joined:
    Apr 25, 2017
    Messages:
    101
    Likes Received:
    14
    Location:
    Malaysia
    Hi Kok Wai, please wrap your code by using BB code editor.
     
    John Joe, Jun 1, 2017
    #2
    Ian likes this.
    1. Advertisements

  3. Ng Kok Wai

    Ian Administrator

    Joined:
    Nov 13, 2005
    Messages:
    32
    Likes Received:
    7
    Thanks, I've edited the post to include this.
     
    Ian, Jun 1, 2017
    #3
    John Joe likes this.
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.