Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <?php
  2. $string = trim(fgets(STDIN));
  3.  
  4. function locate($string){
  5. $coordinates = preg_split('/[\s\,]+/', $string);
  6. $output = [];
  7. //TUVALU
  8. $tuvaluX1 = 1; $tuvaluX2 = 3;
  9. $tuvaluY1 = 1; $tuvaluY2 = 3;
  10.  
  11. //SAMOA
  12. $samoaX1 = 5; $samoaX2 = 7;
  13. $samoaY1 = 3; $samoaY2 = 6;
  14.  
  15. //TONGA
  16. $tongaX1 = 0; $tongaX2 = 2;
  17. $tongaY1 = 6; $tongaY2 = 8;
  18.  
  19. //COOK
  20. $cookX1 = 4; $cookX2 = 9;
  21. $cookY1 = 7; $cookY2 = 8;
  22.  
  23. //TOKELAU
  24. $tokelauX1 = 8; $tokelauX2 = 9;
  25. $tokelauY1 = 0; $tokelauY2 = 1;
  26.  
  27. for($i = 0; $i < count($coordinates); $i+=2){
  28. $x = $coordinates[$i];
  29. $y = $coordinates[$i+1];
  30.  
  31. if(is_numeric($x) && is_numeric($y)){
  32.  
  33. //TUVALU
  34. if($x >= $tuvaluX1 && $x <= $tuvaluX2 &&
  35. $y >= $tuvaluY1 && $y <= $tuvaluY2){
  36. $output[] = "Tuvalu";
  37. }
  38.  
  39. //SAMOA
  40. else if($x >= $samoaX1 && $x <= $samoaX2 &&
  41. $y >= $samoaY1 && $y <= $samoaY2){
  42. $output[] = "Samoa";
  43. }
  44.  
  45. //TONGA
  46. else if($x >= $tongaX1 && $x <= $tongaX2 &&
  47. $y >= $tongaY1 && $y <= $tongaY2){
  48. $output[] = "Tonga";
  49. }
  50.  
  51. //COOK
  52. else if($x >= $cookX1 && $x <= $cookX2 &&
  53. $y >= $cookY1 && $y <= $cookY2){
  54. $output[] = "Cook";
  55. }
  56.  
  57. //TOKELAU
  58. else if($x >= $tokelauX1 && $x <= $tokelauX2 &&
  59. $y >= $tokelauY1 && $y <= $tokelauY2){
  60. $output[] = "Tokelau";
  61. }
  62.  
  63. //IN THE OCEAN
  64. else{
  65. $output[] = "On the bottom of the ocean";
  66. }
  67. }
  68. }
  69. echo implode("\n", $output);
  70. }
  71. locate($string);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement