Advertisement
szabozoltan69

fogado

Aug 29th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.30 KB | None | 0 0
  1. <?php
  2. define('d',"\t");
  3. define('n',"\n");
  4. $f_=file('step10.in',FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  5.  
  6. $ff_=array(); foreach($f_ as $i=>$f){if (strpos($f,'¤')>1) continue;$ff_[]=$f;} $f_=$ff_;unset($ff_);
  7.  
  8. foreach($f_ as $i=>$f){
  9.     if (empty($f)) continue;
  10.     if ($i==0) continue;
  11.     if (($f[0]=='#')&&($i>1)) continue;
  12.     $f=str_replace(',','.',$f);
  13.     $f=str_replace(':',d  ,$f);
  14.     $x=explode(d,$f);
  15.     if (trim($x[3])=='') continue;
  16.     if ($i==1) {$x[0]=99;$x[1]=99; continue;}
  17. //     print_r($x);die;
  18. //    [0] => 1
  19. //    [1] => 0
  20. //    [2] => 2.48
  21. //    [3] => 3.03
  22. //    [4] => 2.69
  23.     if (!is_numeric($x[0])) die ($i.". sor: Nem szám van az első mezőben.".n.$f.n);
  24.     if (!is_numeric($x[1])) die ($i.". sor: Nem szám van a második mezőben.".n.$f.n);
  25.     if (!is_numeric($x[2])) die ($i.". sor: Nem szám van a harmadik mezőben.".n.$f.n);
  26.     if (!is_numeric($x[3])) die ($i.". sor: Nem szám van a negyedik mezőben.".n.$f.n);
  27.     if (!is_numeric($x[4])) die ($i.". sor: Nem szám van az ötödik mezőben.".n.$f.n);
  28. }
  29.  
  30. function fract($a){return substr(str_pad($a,17,'0'),0,8);}
  31.  
  32. $types=$sor0=$sor=array();
  33. foreach($f_ as $i=>$f){
  34.     if (empty($f)) continue;
  35.     if ($i==0) continue;
  36.     if (($f[0]=='#')&&($i>1)) continue;
  37.     $f=str_replace(',','.',$f);
  38.     $f=str_replace(':',d  ,$f);
  39.     $x=explode(d,$f);
  40.     if (trim($x[3])=='') continue;
  41.     if ($i==1) {$csapatok=$x[0];$x[0]=99;$x[1]=99;}
  42.     $min=min($x[2],$x[3],$x[4]); $max=max($x[2],$x[3],$x[4]); $med=$x[2]+$x[3]+$x[4]-$min-$max;
  43.     $max_med=$max-$med; $max_min=$max-$min;
  44.     //$sorrend=array();$sorrendt=array($x[2],$x[3],$x[4]);asort($sorrendt);foreach($sorrendt as $j=>$tmp){$sorrend[]=$j;}
  45.     //$gyozo=''; if ($x[0]!=99) {if ($x[0]>$x[1]) $gyozo=$sorrend[0]; elseif ($x[0]<$x[1]) $gyozo=$sorrend[2]; else $gyozo=$sorrend[1];}
  46.  
  47.     if     ($x[0]> $x[1])  $gyozo=$x[2];
  48.     elseif ($x[0]==$x[1])  $gyozo=$x[3];
  49.     elseif ($x[0]< $x[1])  $gyozo=$x[4]; else $gyozo=0;
  50.     if ($x[0]==99) $inv=""; else $inv="\e[7m";
  51.     $typ=
  52.     ((($x[2]<$x[3]) && ($x[3]<$x[4]))?"ABC":
  53.     ((($x[2]<$x[3]) && ($x[3]==$x[4]))?"xyy":
  54.     ((($x[2]<$x[3]) && ($x[3]>$x[4]))?($x[2]<$x[4]?"ACB":($x[2]>$x[4]?"BCA":"yxy")):
  55.     ((($x[2]==$x[3])&& ($x[3]<$x[4]))?"xxy":
  56.     ((($x[2]==$x[3])&& ($x[3]==$x[4]))?"zzz" :
  57.     ((($x[2]==$x[3])&& ($x[3]>$x[4]))?"yyx":
  58.     ((($x[2]>$x[3]) && ($x[3]<$x[4]))?($x[2]<$x[4]?"BAC":HA($x[2]>$x[4]?"CAB":"xyx")):
  59.     ((($x[2]>$x[3]) && ($x[3]==$x[4]))?"yxx":
  60.     ((($x[2]>$x[3]) && ($x[3]>$x[4]))?"CBA":"NemLehet"
  61.     )))))))));
  62.     $types[]=$typ;
  63.     $sor0[$i]=array($i,$x[0],$x[1],$x[2],$x[3],$x[4],$typ,$min,$med,$max,$max_med/$max_min);
  64.     $sor[$i] =array($typ,fract($max_med/$max_min),$x[0],$x[1],
  65.     ($x[0]> $x[1]?$inv:"").$x[2].($x[0]> $x[1]?"\e[27m":""),
  66.     (($x[0]==$x[1])&& ($x[0]!=99)?$inv:"").$x[3].($x[0]==$x[1]?"\e[27m":""),
  67.     ($x[0]< $x[1]?$inv:"").$x[4].($x[0]< $x[1]?"\e[27m":""),'',
  68.     ($gyozo==$min?$inv:"").$min.($gyozo==$min?"\e[27m":""),
  69.     (($gyozo!=$min)&&($gyozo!=$max)?$inv:"").$med.(($gyozo!=$min)&&($gyozo!=$max)?"\e[27m":""),
  70.     ($gyozo==$max?$inv:"").$max.($gyozo==$max?"\e[27m":""),
  71.     '',$i,);
  72.     //print implode(d,$sor0[$i]).n;
  73. //    [0] => 0 $i obsolete
  74. //    [1] => 3
  75. //    [2] => 1
  76. //    [3] => 1.91
  77. //    [4] => 3.21
  78. //    [5] => 3.78
  79. //    [6] => ABC
  80. //    [7] => 1.91 min
  81. //    [8] => 3.21 med
  82. //    [9] => 3.78 max
  83. //    [10]=> 0.3048128342246 $max_med/$max_min
  84. }
  85. $types=array_values(array_unique($types));
  86. //print_r($types);die;
  87. //foreach($types as $typ){print $typ.' '.str_repeat("-",89).n;}
  88.  
  89. //print_r($sor);die;
  90.  
  91. $out=''; system("clear;echo \e[39m");
  92. //$sor=sort($sor);
  93. foreach($sor as $so){$out.=implode(d,$so).n;}
  94. //foreach($sor as $so){print_r($so);}
  95. $innen=strpos($csapatok,'-'); print "\e[93m".str_repeat(" ",(26-$innen<1?0:26-$innen)).str_replace('#','',$csapatok)."\e[39m".n;
  96. $outt=explode(n,$out);
  97. natsort($outt);
  98. //\e[1m bold - http://misc.flogisoft.com/bash/tip_colors_and_formatting
  99. $elozo='';$sorszin[]="\e[32m";$sorszin[]="\e[39m" /* ez a default */ ; $sorstatusz=0;
  100. foreach($outt as $i=>$out){
  101.     if (empty($out)) continue;
  102.     $x=explode(d,$out);if ($x[2]<$x[3]) $jel='<'; elseif ($x[2]>$x[3]) $jel='>'; else $jel='=';array_splice($x,2,2,$x[2].$jel.$x[3]);$out=implode(d,$x);
  103.     $elej=substr($out,0,4);if ($elej!=$elozo) $sorstatusz=1-$sorstatusz;$elozo=$elej;
  104.     $out=str_replace("  99=99   "," \e[7m? ?\e[27m  ", $out);
  105.     print $sorszin[$sorstatusz].$out.n;
  106.     }
  107. print "\e[39m";
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement