1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #9958

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    // Функция вывода всего списка новостей.
    function show_list($news)
    {
      echo '<html>';
      echo '<head>';
      echo '<title>Последние новости</title>';
      echo '</head>';
      echo '<body>';
      echo '<ul>';
      for ($i = 0; $i < count($news); $i++)
      {
          echo '<li>';
          echo '<a href="news.php?id=' . ($i + 1) . '">'; 
          echo $news[$i];
          echo '</a>';
          echo '</li>';        
      }
    echo '</ul>';    
      echo '</body>';    
      echo '</html>';    
    }
    // Функция вывода конкретной новости.
    function show_item($news, $id)
    {
      echo '<html>';
      echo '<head>';
      echo "<title>Новость #$id</title>";
      echo '</head>';
      echo '<body>';
      echo '<a href="news.php">Вернуться к списку новостей</a>';
      echo '<p>';
      echo $news[$id - 1];
      echo '</p>';    
      echo '<p>';
      echo 'Представьте, что здесь много текста и картинок :)';
      echo '</p>';    
      echo '</body>';    
      echo '</html>';    
    }
    // Точка входа.
    // Создаем массив новостей.
    $news = array();
    $news[0] = 'За качество ответят. Контролировать продукты питания начали по-
    новому.';
    $news[1] = 'Варшава не раскрывает перечень возможных мер против Минска';
    $news[2] = 'Павел Астахов намерен добиваться отставки ряда чиновников 
    Удмуртии';
    // Был ли передан id новости в качестве параметра?
    if (isset($_GET['id']))
    {
      show_item($news, $_GET['id']);
    }
    else
    {
      show_list($news);
    }

    http://otvety.google.ru/otvety/thread?tid=3f83527f1a2f59df

    valera5505, 16 Апреля 2012

    Комментарии (11)
  3. PHP / Говнокод #9909

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    <html>
    <head>
    <title> Тест  </title>
    <h2 align="center"> Тест </h2>
    
    <form action="11.php" method=POST>
    
    <h4> 1. После ссоры в семье, после выговора начальника ищете ли Вы успокоение в спиртных напитках ?</h4> 
    <p><input type=radio name='v1' value='1'> Да </p> 
    <p><input type=radio name='v1' value='0'>Нет </p> 
    ......
    ......
    ......
    
    <h4> 20. Бывают ли у Вас после пьянки слуховые и зрительные галлюцинации ?</h4> 
    <p><input type=radio name='v20' value='1'> Да </p> 
    <p><input type=radio name='v20' value='0'>Нет </p> 
    
    
    <input type=submit value="Ответить">
    
    </form>
    </body>
    </html>
    
    И файл обработчик 11.php
    
    <?php
    $v1 = $_POST['v1'];
    $v2 = $_POST['v2'];
    $v3 = $_POST['v3'];
    $v4 = $_POST['v4'];
    $v5 = $_POST['v5'];
    $v6 = $_POST['v6'];
    $v7 = $_POST['v7'];
    $v8 = $_POST['v8'];
    $v9 = $_POST['v9'];
    $v10 = $_POST['v10'];
    $v11 = $_POST['v11'];
    $v12 = $_POST['v12'];
    $v13 = $_POST['v13'];
    $v14 = $_POST['v14'];
    $v15 = $_POST['v15'];
    $v16 = $_POST['v16'];
    $v17 = $_POST['v17'];
    $v18 = $_POST['v18'];
    $v19 = $_POST['v19'];
    $v20 = $_POST['v20'];
    $over = $v1 + $v2 + $v3 + $v4 + $v5 + $v6 + $v7 + $v8 + $v9 + $v10 + $v11 + $v12 + $v13 + $v14 + $v15 + $v16 + $v17 + $v18 + $v19 + $v20 ; 
    
    
          if ($over > 0 && $over <= 7)   { $ball = "1-7: ранняя стадия, которая длится обычно 10-15 лет."; }
          if ($over > 8 && $over <= 17)  { $ball = "8-17: средняя стадия, длится обычно 2-5 лет"; }
          if ($over > 18 && $over <= 20) { $ball = "18-20: последняя стадия алкоголизма."; }
    
    	  echo "<h4>Результат теста:</h4><p>Вами набрано <b> $over</b> баллов.</p> <p>Результат <b>$ball</b></p>";
    ?>

    The Best Answer on topic ))) http://phpforum.ru/index.php?showtopic=59990&st=0

    vasinsky, 09 Апреля 2012

    Комментарии (11)
  4. Java / Говнокод #9893

    +74

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    public class FSMSmilesMatcher {
    	private Callback mCallback;
    	private State mStartState;
    	
    	public interface Callback {
    		public void onMatch(int matchStart, int matchEnd, int matchId);
    	}
    	
    	//matching whole leading substring cause it's easier to build that way
    	private class State {
    		protected HashMap<String, State> substates; //substring which led to this state + next symbol
    		protected String whole; //whole match
    		protected int matchId;
    		
    		//result = symbols to skip before starting next match
    		protected int process(String input, int matchStart, int matchEnd) {
    			if(matchStart >= input.length() || matchStart >= matchEnd)
    				return 0;
    			if(substates == null) {
    				if(whole == null || whole.length() == 0) {
    					return 0; //shouldn't happen
    				} else if(input.length() >= matchStart + whole.length() && input.substring(matchStart, matchStart + whole.length()).equals(whole)) {
    					mCallback.onMatch(matchStart, matchStart + whole.length(), matchId);
    					return whole.length()> 1 ? whole.length() - 1: 0;
    				}
    			} else if(matchEnd <= input.length()) {
    				State nextState = substates.get(input.substring(matchStart, matchEnd));
    				if(nextState != null)
    					return nextState.process(input, matchStart, matchEnd + 1);
    			}
    			return 0;
    		}
    	}
    	
    	//checks only next symbol
    	//removes long tails (into single 'whole' match)
    	private class OptimizedState extends State{
    		private OptimizedState(State inState) {			
    			if(inState.substates != null) {
    				this.substates = new HashMap<String, State>();
    				for(String key : inState.substates.keySet()) {
    					this.substates.put(key.substring(key.length()-1, key.length()).toLowerCase(), new OptimizedState(inState.substates.get(key)));
    				}				
    				if(this.substates.size() == 1) {
    					State subState = this.substates.values().iterator().next();
    					if(subState.substates == null) {
    						this.substates = null;
    						this.whole = subState.whole;
    						this.matchId = subState.matchId;
    					}
    				}
    			} else {
    				this.whole = inState.whole;
    				this.matchId = inState.matchId;
    			}
    		}
    		
    		@Override
    		protected int process(String input, int matchStart, int matchEnd) {
    			if(matchStart >= input.length() || matchStart >= matchEnd)
    				return 0;
    			if(substates == null) {
    				if(whole == null || whole.length() == 0) {
    					return 0; //shouldn't happen
    				} else if(input.length() >= matchStart + whole.length() && input.substring(matchStart, matchStart + whole.length()).equalsIgnoreCase(whole)) {
    					mCallback.onMatch(matchStart, matchStart + whole.length(), matchId);
    					return whole.length()> 1 ? whole.length() - 1: 0;
    				}
    			} else if(matchEnd <= input.length()) {
    				State nextState = substates.get(input.substring(matchEnd - 1, matchEnd).toLowerCase());
    				if(nextState != null)
    					return nextState.process(input, matchStart, matchEnd + 1);
    			}
    			return 0;
    		}
    	}
    
    	...	
    
    	private HashMap<String, State> generateSubstates(List<ImageMatchElement> matches, String lead) {
    		List<String> variants = new ArrayList<String>();
    		HashMap<String, Integer> completeMatches = new HashMap<String, Integer>();
    		
    		...		
    
    		if(variants.size() == 0) {
    			return null;
    		} else {
    			HashMap<String, State> substates = new HashMap<String, State>();
    			for(String variant: variants) {
    				State state = new State();
    				if(completeMatches.containsKey(variant)) {
    					state.whole = variant;
    					state.matchId = completeMatches.get(variant);
    				} else {
    					state.substates = generateSubstates(matches, variant);
    				}
    				substates.put(variant, state);
    			}
    		...

    Требовалось заменить коды смайликов в текстовом сообщении заменить на соответствующие картинки (типа ":* привет :-p ^_^" заменить на "[картинка] привет [картинка] [картинка]".

    enikey87, 09 Апреля 2012

    Комментарии (11)
  5. PHP / Говнокод #9851

    +167

    1. 1
    unlink(__FILE__);

    __proto__, 03 Апреля 2012

    Комментарии (11)
  6. Си / Говнокод #9774

    +134

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    /* страйкер, почини trim */
      while (1)
        {
          file_ptr start;
          int i;
          long c;
    
          /* See if the next `string_min' chars are all graphic chars.  */
        tryline:
          if (stop_point && address >= stop_point)
    	break;
          start = address;
          for (i = 0; i < string_min; i++)
    	{
    	  c = get_char (stream, &address, &magiccount, &magic);
    	  if (c == EOF)
    	    {
    	      free (buf);
    	      return;
    	    }
    	  if (! STRING_ISGRAPHIC (c))
    	    /* Found a non-graphic.  Try again starting with next char.  */
    	    goto tryline;
    	  buf[i] = c;
    	}

    Раз уж вспоминаем дрѣвния говны

    Written by Richard Stallman <[email protected]>
    and David MacKenzie <[email protected]>.

    bugmenot, 26 Марта 2012

    Комментарии (11)
  7. PHP / Говнокод #9745

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $version = (int)$_GET['version'];
    	
    	if (!empty($version))
    	{
    		$version = '1.4.6.2';
    	}
    	else
    	{
    		$version = '1.4.6.2';
    	}

    Ну и на кой?

    ibnLoky, 23 Марта 2012

    Комментарии (11)
  8. ActionScript / Говнокод #9704

    −122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    var daytoday:String;
    var today = new Date();
    var monthtoday;
    var year = today.getFullYear(); 
    var timer:Timer = new Timer(1000);
    timer.addEventListener(TimerEvent.TIMER, clock);
    timer.start();
    function clock(e:TimerEvent):void {
       var datetoday:Date=new Date();
       switch (datetoday.day) {
           case 0:
           daytoday="ВОСКРЕСЕНЬЕ";
           break;
           case 1:
           daytoday="ПОНЕДЕЛЬНИК";
           break;
           case 2:
           daytoday="ВТОРНИК";
           break;
           case 3:
           daytoday="СРЕДА";
           break;
           case 4:
           daytoday="ЧЕТВЕРГ";
           break;
           case 5:
           daytoday="ПЯТНИЦА";
           break;
           case 6:
           daytoday="СУББОТА";
           break;
       }
       дэй_оф_вик.text=String(daytoday);
     
       switch (datetoday.month) {
           case 0:
           monthtoday="Января";
           break;
           case 1:
           monthtoday="Февраля";
           break;
           case 2:
           monthtoday="Марта";
           break;
           case 3:
           monthtoday="Апреля";
           break;
           case 4:
           monthtoday="Мая";  
           break;  
           case 5:  
           monthtoday="Июня";
           break;
           case 6:
           monthtoday="Июля";
           break;
           case 7:
           monthtoday="Августа";
           break;
           case 8:
           monthtoday="Сентября";
           break;
           case 9:
           monthtoday="Октября";
           break;
           case 10:
           monthtoday="Ноября";
           break;
           case 11:
           monthtoday="Декабря";
           break;
       }
       month.text=String(monthtoday);  
       day.text=String(datetoday.date);
       data_txt.text = year;
    }

    Мне больше всего нравится 33 строка...

    kyzi007, 18 Марта 2012

    Комментарии (11)
  9. C++ / Говнокод #9687

    +994

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    int main()
    {   
       //выводит на экран среднее арифметическое чисел 1, 3, 5
       std::cout << Mean + 1 + 3 + 5 << std::endl;
       //выводит на экран среднее геометрическое чисел 2, 4, 8
       std::cout << Mean * 2 * 4 * 8 << std::endl;
    }
    
    //реализация
    
    class CMean
    {
       mutable double out;
       mutable size_t cnt;
       mutable size_t type;
    public:
       CMean(): out(0), cnt(0), type(-1)  {}
       CMean& operator + (double n)
       {
          return type = 0, out+= n, ++cnt, *this;   
       }
       CMean& operator * (double n)
       {   
          return (type == (size_t)-1 ? type = 1, out = 1 : 0), out*= n, ++cnt, *this;   
       }
       size_t reset() const {return type = -1, out = cnt = 0;};
       friend std::ostream& operator << (std::ostream&, const CMean&);   
    } Mean;
    
    std::ostream& operator << (std::ostream& _os, const CMean& _arith)
    {
       return _os << (!_arith.type ? _arith.out / _arith.cnt : std::pow(_arith.out, 1.0 / _arith.cnt)) + _arith.reset();
    }

    Вывод на экран арифметической и геометрической прогрессии.

    gooseim, 15 Марта 2012

    Комментарии (11)
  10. Java / Говнокод #9615

    +78

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    Drawable d = getResources().getDrawable(R.drawable.screen_width);
            int width = d.getMinimumWidth();
            switch (width) {
                case 1024:
                    CAMERA_WIDTH = 1024;
                    CAMERA_HEIGHT = 600;
                    break;
                case 800:
                    CAMERA_WIDTH = 800;
                    CAMERA_HEIGHT = 480;
                    break;
                case 480:
                    CAMERA_WIDTH = 480;
                    CAMERA_HEIGHT = 320;
                    break;
                case 320:
                    CAMERA_WIDTH = 320;
                    CAMERA_HEIGHT = 240;
                    break;
                default:
                    CAMERA_WIDTH = 800;
                    CAMERA_HEIGHT = 480;
                    break;
            }

    Вот так автор определял размер экрана в Android...по размеру загруженной картинки в ресурсах
    Про getResources().getConfiguration().screen Layout наверное он не знал...

    TeknoMatik, 05 Марта 2012

    Комментарии (11)
  11. C++ / Говнокод #9603

    +997

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    static std::string printFloatNumber(float num,bool friendly=false)
    {
    	std::ostringstream out ;
    
    	if(friendly)
    	{
    		char tmp[100] ;
    		std::string units[4] = { "B/s","KB/s","MB/s","GB/s" } ;
    
    		int k=0 ;
    		while(num >= 800.0f && k<5)
    			num /= 1024.0f,++k;
    
    		sprintf(tmp,"%3.2f %s",num,units[k].c_str()) ;
    		return std::string(tmp) ;
    	}
    	else
    	{
    		out << num ;
    		return out.str() ;
    	}
    }

    Исходники RetroShare - это просто шедевр!

    rat4, 04 Марта 2012

    Комментарии (11)