Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <title>Longest Increasing Sequence</title>
- <meta charset="UTF-8"/>
- </head>
- <body>
- <?php
- $input_1 = array(2, 3, 4, 1, 50, 2 ,3, 4, 5);
- $input_2 = array(8, 9, 9, 9, -1, 5, 2, 3);
- $input_3 = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
- $input_4 = array(5, -1, 10, 20, 3, 4);
- $input_5 = array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
- function longest_element($example){
- echo "За масив със стойности: ";
- foreach($example as $value){
- echo $value." ";
- }
- echo "<br/> <h3>Резултата е:</h3> <br/>";
- $count= count($example);
- $result = array();
- $cycle=array();
- for($i=0; $i<count($example); $i++){
- $element = $example[$i];
- array_push($cycle, $element);
- echo $element." ";
- if($i!=($count-1) && $element>=$example[$i+1] ){
- echo "<br>";
- array_push($result, $cycle);
- unset($cycle);
- $cycle=array();
- }
- else if ($i==($count-1)){
- array_push($result, $cycle);
- }
- rsort($result);
- }
- //echo "<pre>".print_r($result, true)."</pre>";
- echo "<br/> Longest: ";
- foreach($result[0] as $value){
- echo $value." ";
- }
- echo "<br/>";
- echo "<hr>";
- echo "<br/>";
- }
- longest_element($input_1)."<br/>";
- longest_element($input_2)."<br/>";
- longest_element($input_3)."<br/>";
- longest_element($input_4)."<br/>";
- longest_element($input_5)."<br/>";
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement