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

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

    +148

    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
    <?
    	$optSelect['10'] = ($_REQUEST['sort_count']=='10') ? 'selected' : '';
    	$optSelect['20'] = ($_REQUEST['sort_count']=='20') ? 'selected' : '';
    	$optSelect['50'] = ($_REQUEST['sort_count']=='50') ? 'selected' : '';
    	$optSelect['all'] = ($_REQUEST['sort_count']=='all') ? 'selected' : '';
    	
    	$remParams = array('sort_count');
            //функция GetCurPageParam в битрикс возвращает путь к текущей странице с добавлением/удалением параметров (автор поста) 
    	$optValueURI['10'] = $APPLICATION->GetCurPageParam('sort_count=10', $remParams);
    	$optValueURI['20'] = $APPLICATION->GetCurPageParam('sort_count=20', $remParams);
    	$optValueURI['50'] = $APPLICATION->GetCurPageParam('sort_count=50', $remParams);
    	$optValueURI['all'] = $APPLICATION->GetCurPageParam('sort_count=all', $remParams);
    			
    	$optValue['10'] = $siteURL . $optValueURI['10'];
    	$optValue['20'] = $siteURL . $optValueURI['20'];
    	$optValue['50'] = $siteURL . $optValueURI['50'];
    	$optValue['all'] = $siteURL . $optValueURI['all'];
    ?>
    <select onChange="location=this.value">
    	<option <?=$optSelect['10']?> value="<?=$optValue['10']?>">10</option>
    	<option <?=$optSelect['20']?> value="<?=$optValue['20']?>">20</option>
    	<option <?=$optSelect['50']?> value="<?=$optValue['50']?>">50</option>
    	<option <?=$optSelect['all']?> value="<?=$optValue['all']?>">Все</option>
    </select>

    Реализация Селекта количества выводимых элементов на странице. Сайт делал топовый партнёр 1c-Bitrix.
    Я думаю, что разумнее было бы сделать так:
    $arPages = array(10, 20, 50, 'all');
    foreach ($arPages as $page) {?>
    <option <?if($page == $_REQUEST['sort_count']){?>selected<?}?>>$page</option>
    <?}?>
    Ну и для сабмита можно какую нибудь нормальную функцию в JS написать.

    Cool-Di, 26 Ноября 2010

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

    +148

    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
    for($i = 5; $i <= 11; $i++)
    {
        echo "<tr>\n";
        echo "<td valign=\"top\">\n<b>$i</b>\n</td>\n\n";
        /* для каждого дня */
        foreach($dayslt as $day)
        {
          echo "<td>\n";
          for($lesson_num = 1; $lesson_num <= 6; $lesson_num++)
          {
           echo "<input type=\"text\" name=\"lesson[$i][$day][$lesson_num]\"><br/>\n";
          }
          echo "</td>\n\n";
        }
        echo "</tr>\n\n";
    }

    какая-то хуйня по вводу расписания, хз

    varg242, 19 Ноября 2010

    Комментарии (71)
  4. PHP / Говнокод #4432

    +148

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function ArrayTopics() {
    	global $db;
    	$db->Select('news_topics','');
    	$top = array();
    	while($topic=$db->FetchRow()) {
    		$top[$topic['id']] = $topic;
    	}
    	return $top;
    }

    Из той же русской CMS... опять PHP костыль вместо нормального SQL запроса...

    Мартин, 24 Октября 2010

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

    +148

    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
    77. 77
    78. 78
    $temp_leader=array();
    //получаю список всех пользователей
    $resUser = CUser::GetList($by = 'ID', $order = 'ASC', array("ACTIVE"=>"Y"));
    while ($arUser = $resUser->Fetch())
    {
            //получаю для конкретного юзера элементы
            $resElementUser = CIBlockElement::GetList(Array(), Array('ACTIVE'=>"Y", 'IBLOCK_ID'=>"45", 'CREATED_BY'=>$arUser['ID'], ">PROPERTY_POINT_FISH"=>"1"), false, false, Array("PROPERTY_POINT_FISH", "ID"));
            $p=0;
            while ($arElementUser = $resElementUser->Fetch())
            {
                    $p++;
                    $arElementUser111[] = $arElementUser;
                    $tempElementUser[] =  $arElementUser;
            }
            for ($i=0; $i<$p; $i++)
            {
                    $temp_fish[$i] = $arElementUser111[$i]["PROPERTY_POINT_FISH_VALUE"];
            }
            //надо подсчитать количество видов у пользователя
            if (count($temp_fish)>0)
            {
                    if (count($temp_fish) == 1)
                    {
                            $count_fish = 1;
                    }
                    else
                    {
                            $res = array_count_values($temp_fish);
                            $count_fish = count($res);
                    }
                    //если еще меньше 6 лидеров то надо в массив писать лидера без проверок
                    if (count($temp_leader)<6)
                    {
                            $temp_leader[]=$count_fish;
                            $temp_login[]= get_user_name($arUser['ID']);
                            $temp_user[]=$arUser['ID'];
                    }
                    //иначе выявляю min и запоминаю позицию его и если у текущего пользователя больше min то пишем в массив
                    else
                    {
                            $min = $temp_leader[0];
                            $temp_pos = 0;
                            for ($i=1; $i<7; $i++)
                            {
                                    if ($temp_leader[$i] < $min) {$min=$temp_leader[$i]; $temp_pos = $i;}
                            }
                            if ($count_fish > $min)
                            {
                                    $temp_leader[$temp_pos] = $count_fish;
                                    $temp_login[$temp_pos]= get_user_name($arUser['ID']);
                                    $temp_user[$temp_pos] = $arUser['ID'];
                            }
                    }
                    unset($temp_fish);
                    unset($tempElementUser);
                    unset($arElementUser111);
            }
    }
    for ($i=0;$i<count($temp_leader);$i++)
    {
            for ($j=count($temp_leader)-1; $j>$i; $j--)
            {
                    if ($temp_leader[$j-1]<$temp_leader[$j])
                    {
                            $per = $temp_leader[$j-1];
                            $temp_leader[$j-1] = $temp_leader[$j];
                            $temp_leader[$j] = $per;
    
                            $per1 = $temp_login[$j-1];
                            $temp_login[$j-1] = $temp_login[$j];
                            $temp_login[$j] = $per1;
    
                            $per2 = $temp_user[$j-1];
                            $temp_user[$j-1] = $temp_user[$j];
                            $temp_user[$j] = $per2;
                    }
            }
    }

    atarix12, 17 Сентября 2010

    Комментарии (8)
  6. PHP / Говнокод #4225

    +148

    1. 1
    2. 2
    3. 3
    4. 4
    if( !$this->dirsmodel->isExist(array('alias' => $_POST['alias']))) {
        $this->messages[] = 'Такой алиас уже существует';
        return $this->redirect("admin/dirs/#" . $cat_id);
    }

    Говнокод тонкий особый. Кто найдёт получит пиченьку

    DrFreez, 11 Сентября 2010

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

    +148

    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
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    struct _elem
    {
        int x, y, z, num;
        bool r;
        long long square;
        void read(int i)
        {
            cin >> x >> y >> z;
            num = i;
            square = 0;
        }
    
        friend bool operator<(_elem a, _elem b)
        {
            if ( a.z == b.z)
            {
                return a.r == true;
            }
            else
            {
                return a.z < b.z;
            }
        }
    };
    
    _elem mas[500000];
    bool vis[500000];
    int main()
    {
        int N, W, L;
        cin >> N >> W >> L;
    
        for ( int i = 0; i < N; i++)
        {
            mas[i].read(i);
            mas[i].r = false;
            mas[i + N].read(i);
            mas[i + N].r = true;
            mas[i].square = mas[i + N].square = abs(mas[i].x - mas[i + N].x) * abs(mas[i].y - mas[i + N].y);
            vis[i] = vis[i + N] = false;
        }
    
        sort(mas, mas + 2 * N);
    
        long long square = 0;
        int count = 0;
        int min = -1;
        for ( int i = 0; i < 2 * N; i++)
        {
            if ( mas[i].r == false)
            {
                square += mas[i].square;
                count++;
            }
            else
            {
                square -= mas[i].square;
                count--;
            }
            if ( square == W * L)
            {
                if (min == -1 || count < min)
                {
                    min = count;
                }
            }
        }
       
        if ( min == -1)
        {
            cout << "NO" << endl;
        }
        else
        {
            cout << "YES" << endl;
            count = 0;
            square = 0;
            int i = 0;
            while (count != min || square != W * L)
            {
                if ( mas[i].r == false)
                {
                    square += mas[i].square;
                    count++;
                    vis[mas[i].num] = true;
                }
                else
                {
                    square -= mas[i].square;
                    count--;
                    vis[mas[i].num] = false;
                }
                i++;
            }
            cout << min << endl;
            }
         }
    }

    hromjo, 28 Августа 2010

    Комментарии (13)
  8. PHP / Говнокод #3980

    +148

    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
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    <?php
    if (!$action){
    	echoheader('addnews', $echo['header']);
    ?>
    
    <form method="post" name="addnews" action="<?=$PHP_SELF; ?>" onsubmit="return process_form(this)">
    
    
    
    <!-- короткая -->
    <fieldset id="short"><legend><?=$echo['short']; ?></legend>
    
    <?
    	echo run_filters('new-advanced-options', 'short');
    ?>
    
    
    <textarea name="short_story" tabindex="4"></textarea>
    </fieldset>
    
    
    
    <!-- кнопки -->
    <fieldset id="actions"><legend><?=$echo['actions']; ?></legend>
    <input type="submit" value="<?=$echo['add']; ?>" accesskey="s">
    </fieldset>
    
    
    
    
    
    <?
    	}
    ?>
    
    <fieldset id="date"><legend><?=$echo['date']; ?></legend>
    <input type="text" name="day" size="10" maxlength="2" value="<?=date('d'); ?>" title="<?=$echo['calendar']['day']; ?>" readonly>
    
    <input type="text" name="month" size="10" maxlength="10" value="<?=date('M'); ?>" readonly>
    
    
    
    <input type="text" name="year" maxlength="4" value="<?=date('y'); ?>" title="<?=$echo['calendar']['year']; ?>" readonly> <input type="text" name="hour" maxlength="2" value="<?=date('H', (time() + $config_date_adjust * 60)); ?>" title="<?=$echo['calendar']['hour']; ?>" readonly>:<input type="text" name="minute" maxlength="2" value="<?=date('i', (time() + $config_date_adjust * 60)); ?>" title="<?=$echo['calendar']['minute']; ?>" readonly>:<input type="text" name="second" maxlength="2" value="<?=date('s', (time() + $config_date_adjust * 60)); ?>" title="<?=$echo['calendar']['second']; ?>" readonly>
    </fieldset>
    
    
    
    </div></fieldset>
    
    <input type="hidden" name="mod" value="addnews">
    <input type="hidden" name="action" value="doaddnews">
    </form>
    
    <?
    	echofooter();
    
    
    // ********************************************************************************
    // Do add News to DB
    // ********************************************************************************
    if ($action == 'doaddnews'){
    	if (($added_time = strtotime($day.' '.$month.' '.$year.' '.$hour.':'.$minute.':'.$second)) == -1){
    		$added_time = (time() + $config_date_adjust * 60);
    	}
    
    	if (!$title){
    		$title = substr($short_story, 0, 10).'...';
    	}
    
    	$id = $sql->last_insert_id('news', '', 'id') + 1;
    
    	run_actions('new-save-entry');
    
    	$sql->insert(array(
    	'table'	 => 'news',
    	'values' => array(
    				'date'	   => $added_time,
    				'author'   => $member['username'],
    				'title'	   => replace_news('add', $title),
    				'short'	   => strlen(replace_news('add', $short_story)),
    				'full'	   => strlen(replace_news('add', $full_story)),
    				'avatar'   => $avatar,
    				'category' => $category,
    				'url'	   => ($url ? my_namespace($url) : my_namespace(totranslit($title))),
    				'hidden'   => (($config_approve_news == 'yes' and $member['level'] > 2) ? true : false)
    				)
    	));
    
    	$sql->insert(array(
    	'table'	 => 'story',
    	'values' => array(
    				'post_id' => $id,
    				'short'	  => replace_news('add', $short_story),
    				'full'	  => replace_news('add', $full_story)
    				)
    	));
    
    	run_actions('new-save-entry');

    dimiork, 14 Августа 2010

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

    +148

    1. 1
    Block *** Cells;

    Лаконичная семантика C++.
    Глядишь на код -- и всё понятно: Cells - это указатель массива указателей на массивы указателей объектов класса Block.
    А устно с первого раза хрен выговоришь.

    maniac, 30 Июля 2010

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

    +148

    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
    #include <cstdio>
    #include <memory.h>
    
    #define maxn 18
    
    char c[maxn][maxn];
    int d[1 << maxn];
    
    int main()
    {
      freopen("network.in", "rt", stdin);
      freopen("network.out", "wt", stdout);
      
      int n; scanf("%d", &n);
      for (int i = 0; i < n; i++)
        scanf("%s", c[i]);
        
      memset(d, 0, sizeof(d));
      
      for (int k = 0; k < (1 << n); k++)
        for (int i = 0; i < n; i++)
          for (int j = 0; j < n; j++)
            if (c[i][j] == 'Y' && k & (1 << i) && k & (1 << j) && d[k - (1 << i) - (1 << j)] + 2 > d[k])
              d[k] = d[k - (1 << i) - (1 << j)] + 2;
              
      int max = 0;
      for (int i = 0; i < (1 << n); i++)
        if (d[i] > max)
          max = d[i];
          
      printf("%d\n", max);
      
      return 0;
    }

    ACM-задачка на динамику по подмножествам.
    Кто поймет, тому 5 ;)

    ystepanov, 22 Июля 2010

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

    +148

    1. 1
    $isOccupy=($valdet['isOccupy']=='1')?0:1;

    а все по тому что кое кто перепутал логику атрибута=\

    nur, 06 Июля 2010

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