Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <?php
  2. /**
  3. * Auto-generated code below aims at helping you parse
  4. * the standard input according to the problem statement.
  5. **/
  6.  
  7. fscanf(STDIN, "%d",
  8. $n // the number of temperatures to analyse
  9. );
  10. $temps = stream_get_line(STDIN, 256 + 1, "\n"); // the n temperatures expressed as integers ranging from -273 to 5526
  11. $temps_arr = explode(" ", $temps);
  12. // Write an action using echo(). DON'T FORGET THE TRAILING \n
  13. // To debug (equivalent to var_dump): error_log(var_export($var, true));
  14.  
  15. //echo("result\n");
  16. //print_r($temps_arr);
  17. error_log(var_export($temps, true));
  18.  
  19. $temps_int_arr=[];
  20. foreach ($temps_arr as $key=>$value)
  21. {
  22. $temps_int_arr1[]=(int)$value;
  23. $temps_int_arr[]=abs((int)$value);
  24. }
  25.  
  26. $min=5526;
  27. $min_index=0;
  28. foreach ($temps_int_arr as $key=>$value)
  29. {
  30. if ($value<$min)
  31. { $min=$value;
  32. $min_index=$key;
  33. }
  34. }
  35.  
  36. $save_value=0;
  37. $save_neg_value=0;
  38. // error_log(var_export($min, true));
  39. foreach ($temps_int_arr1 as $value){
  40.  
  41. if ($value == $min){
  42. $save_value = $value;
  43. }
  44. else if ($value == -$min){
  45. $save_neg_value = $value;
  46. }
  47.  
  48. }
  49. // error_log(var_export($save_value, true));
  50. // error_log(var_export($save_neg_value, true));
  51.  
  52. if ($save_neg_value == -$save_value)
  53. {
  54. echo ($save_value."\n");
  55. }
  56. else if ($save_neg_value < $save_value && $save_neg_value!=0)
  57. {
  58. echo($save_neg_value."\n");
  59. }
  60. else
  61. {
  62. echo ($save_value."\n");
  63. }
  64.  
  65. //echo($temps_int_arr[$min_index]."\n");
  66. //$table[$max]=0;
  67.  
  68. // $min=array_search(min($temps_int_arr),$temps_int_arr);
  69.  
  70. // if ( array_search($temps_int_arr[$min], $temps_int_arr1)==false && )
  71. // {
  72. // echo($temps_int_arr[$min]."\n");
  73. // }
  74. // else
  75. // {
  76. // echo(-$temps_int_arr[$min]."\n");
  77. // }
  78.  
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement