fork(2) download
  1. <?php
  2.  
  3. /*
  4. current
  5. 2000 = (2000) 2001 2002 2003 2004
  6. 2001 = 2000 (2001) 2002 2003 2004
  7. 2002 = 2000 2001 (2002) 2003 2004
  8. 2003 = 2001 2002 (2003) 2004 2005
  9. 2004 = 2002 2003 (2004) 2005 2006
  10. 2005 = 2003 2004 (2005) 2006 2007
  11. 2006 = 2004 2005 (2006) 2007 2008
  12. 2007 = 2005 2006 (2007) 2008 2009
  13. 2008 = 2005 2006 2007 (2008) 2009
  14. 2009 = 2005 2006 2007 2008 (2009)
  15. */
  16.  
  17. $year = array("2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009");
  18. $year_current = "2004"; # output = 2002 2003 (2004) 2005 2006
  19.  
  20. print '2000 = ' . lebedevIt($year, '2000') . "\n";
  21. print '2001 = ' . lebedevIt($year, '2001') . "\n";
  22. print '2002 = ' . lebedevIt($year, '2002') . "\n";
  23. print '2003 = ' . lebedevIt($year, '2003') . "\n";
  24. print '2004 = ' . lebedevIt($year, '2004') . "\n";
  25. print '2005 = ' . lebedevIt($year, '2005') . "\n";
  26. print '2006 = ' . lebedevIt($year, '2006') . "\n";
  27. print '2007 = ' . lebedevIt($year, '2007') . "\n";
  28. print '2008 = ' . lebedevIt($year, '2008') . "\n";
  29. print '2009 = ' . lebedevIt($year, '2009') . "\n";
  30.  
  31. function lebedevIt($years, $yearCurrent) {
  32. $length = count($years);
  33. $max = ($length - 5);
  34.  
  35. $current = array_search($yearCurrent, $years);
  36.  
  37. $start = ($current - 2);
  38.  
  39. if ($current < 3) {
  40. $start = 0;
  41. }
  42.  
  43. if ($start > $max) {
  44. $start = $max;
  45. }
  46.  
  47. $years[$current] = '(' . $years[$current] . ')';
  48.  
  49. $output = array_slice($years, $start, 5);
  50.  
  51. return implode(' ', $output);
  52. }
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
2000 = (2000) 2001 2002 2003 2004
2001 = 2000 (2001) 2002 2003 2004
2002 = 2000 2001 (2002) 2003 2004
2003 = 2001 2002 (2003) 2004 2005
2004 = 2002 2003 (2004) 2005 2006
2005 = 2003 2004 (2005) 2006 2007
2006 = 2004 2005 (2006) 2007 2008
2007 = 2005 2006 (2007) 2008 2009
2008 = 2005 2006 2007 (2008) 2009
2009 = 2005 2006 2007 2008 (2009)