Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.94 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html lang="lt">
  3.     <head>
  4.         <title>Kontrolinis 1 Variantas</title>
  5.         <meta charset="utf-8">
  6.     </head>
  7.     <body>
  8.         <h2>Julijos kolis</h2>
  9.         <h3>1 Užduotis - temperatūros</h3>
  10.         <?php
  11.         // Masyve saugomas kiekvieno metų mėnesio temp. vidurkis.
  12.         // Parašykite funckiją, kuri sugeneruotų atsitiktinę mėnesio temp. [-2;15]...
  13.         // Čia padaryta, kad išvestų temp. didesnes už 10 per metus.
  14.             $temp = array();
  15.             $n = 12;
  16.            
  17.             $mins = 0;
  18.             $maxs = 0;
  19.             $men = 0;
  20.             //$vidutine = 0;
  21.             $men = array();
  22.             $sk = 0;
  23.            
  24.             function randata($mins,$maxs){
  25.                 $randtemp = 0;
  26.                 $randtemp = rand($mins, $maxs);
  27.                 return $randtemp ;
  28.             }
  29.            
  30.             function isrinkti($temp){
  31.                 for($j=0; $j< 12; $j++){
  32.                     $t = $temp[$j];
  33.                     $men = ($j+1);
  34.                     //$vidutine = ($temp/12);
  35.                     //echo "Vidutinė metų temp. yra ".$vidutine."<br>";
  36.                 if($t > 10) echo $t." C; Men: ".$men."<br>";
  37.                 }
  38.             }
  39.            
  40.             for($x=0; $x < $n; $x++){
  41.                 $men = $x;
  42.                 if($x<3){
  43.                     $temp[$x] = randata(-2,15);
  44.                     }
  45.                 else if($x>=3 && $x<6){
  46.                     $temp[$x] = randata(15,35);
  47.                     }
  48.                 else if($x>=6 && $x<9){
  49.                     $temp[$x] = randata(10,-2);
  50.                     }
  51.                 else if($x>=9 && $x<12){
  52.                     $temp[$x] = randata(-30,0);
  53.                     }
  54.                 else $temp[$x] = "Belekas";
  55.             }
  56.                 isrinkti($temp);
  57.         ?>
  58.         <hr>
  59.         <h3>2 Užduotis - matricos</h3>
  60.         <?php
  61.         // Failo duom.txt pirmoje eilutėje parašytas kvadratinės matricos dydis.
  62.         // Toliau surašytos dviejų matricų elementų reikšmės. Daugyba.
  63.                 $ran = rand(-5,5);
  64.                 echo $ran."<br><br>";
  65.                
  66.                 $file = "duom.txt";
  67.                 $cont = file_get_contents($file);
  68.                 $cont = str_replace("\n", " ", $cont);
  69.                
  70.                 $skaiciai = explode(" ", $cont);
  71.            
  72.                
  73.                 $eil = $skaiciai[0];
  74.                 $stulp = $skaiciai[1];
  75.            
  76.                 $eil = (int)$eil;
  77.                 $stulp = (int)$stulp;
  78.                
  79.                 $n = $eil*$stulp;
  80.                
  81.                
  82.                 for($x = 2;$x<$n+2; $x++){
  83.                     $skaiciai[$x] = (int)$skaiciai[$x];
  84.                    
  85.                         $skaiciai[$x]*=$ran;
  86.                 }
  87.                
  88.                 $rez = "";
  89.                 $ind = 2;
  90.                
  91.                 for($i = 0; $i< $eil;$i++){
  92.                     for($j = 0; $j < $stulp;$j++){
  93.                     $rez .= $skaiciai[$ind++]. " ";
  94.                     }
  95.                     $rez .= "\n";
  96.                
  97.                 }
  98.                
  99.                 file_put_contents("rez.txt", $rez);
  100.                
  101.                
  102.         ?>
  103.         <hr>
  104.         <h3>3 Užduotis - mašinos</h3>
  105.         <?php
  106.         // Inicilizuoja dvimatį masyvą su metais. Išveda mašinų modelius
  107.         // naujesnius už 2008 m.
  108.         $cars = array(
  109.         'AlfaRomeo' => array(
  110.         '156' => 2006,
  111.         '159' => 2007,
  112.         'Brera' => 2007,
  113.         'Gulietta' => 2018
  114.         ),
  115.        
  116.         'Opel' => array(
  117.         'Astra' => 2012,
  118.         'Signum' => 2002,
  119.         'Corsa' => 1997,
  120.         'Ampera' => 2018
  121.         ),
  122.        
  123.         'Audi' => array(
  124.         'Bulka' => 1997,
  125.         'BulkaII' => 2002,
  126.         'BAulkaIII' => 2004,
  127.         'BulkaIV' => 2009
  128.         )
  129.        
  130.         );
  131.        
  132.         foreach($cars as $brand => $brcars){
  133.         krsort($brcars);
  134.        
  135.         foreach($brcars as $model => $year){
  136.         $y = (int)$year;
  137.                     if($y > 2008) echo $model."<br>";
  138.         }
  139.         }
  140.         ?>
  141.         <hr>
  142.     </body>
  143. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement