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

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

    +141

    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
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int n, m, c, b, f = 0;
        cin >> n >> m;
        int A[n][m];
        for(int i = 0; i < n; i++ )
        {
            for(int j = 0; j < m; j++)
            {
                cin >> A[i][j];
            }
        }
    
            for(int i = 0; i < n; i++ )
            {
                b = A[i][0];
                for(int j = 0; j < m; j++)
                {
                c = A[0][j];
                for(int a = 0; a < n; a++)
                 {
    
                     if(c < A[0][a])
                     {
                         c = A[0][a];
                     }
                 }
                 for(int k = 0; k < m; k++)
                 {
    
                     if(b > A[k][0])
                     {
                        b = A[k][0];
                     }
                 }
    
    
                 if(b == c)
                 {
                     f++;
                 }
                }
            }
                cout << f;
                return 0;
    }

    Задана матрица K, содержащая n строк и m столбцов. Седловой точкой этой матрицы назовем элемент, который одновременно является минимумом в своей строке и максимумом в своем столбце.

    Найдите количество седловых точек заданной матрицы.
    Вроде всё правильно, а выдаёт, что есть необработаное исключение.Что не так?

    alexsid13, 20 Февраля 2012

    Комментарии (20)
  3. Pascal / Говнокод #9430

    +88

    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
    var A:array of record
      Foo: integer;
    end;
    
    function NewNode: integer;
    begin
      SetLength(A, Length(A)+1);
      Result := High(A);
      // возвращаем не указатель на последний элемент,
      // а номер последнего элемента, потому что массив динамический и указатели нестабильны
    end;
    
    procedure DoSmth(var i: integer);
    var
      n1,n2: integer;
    begin
      n1 := NewNode;
      n2 := NewNode;
      // дальше что-то проделывааем над A[n1] и A[n2]
      i := A[n1].Foo + A[n2].Foo;
    end;
    
    var
      NewIndex: integer;
    begin
      NewIndex := NewNode;
      DoSmth(A[NewIndex].Foo);
    end.

    Угадайте, почему это не будет работать и приведёт к порче памяти.

    TarasB, 15 Февраля 2012

    Комментарии (20)
  4. JavaScript / Говнокод #9348

    +148

    1. 1
    http://digest.subscribe.ru/inet/review/n763622828.html

    Статья прелесть. document.write() в наше-то время...

    0rt, 08 Февраля 2012

    Комментарии (20)
  5. ActionScript / Говнокод #9313

    −125

    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
    public function hasServiceMan ():Object
    {
    	if (_data)
    	{
    		try
    		{
    			return _data.team.repairman;
    		}
    		catch (er:Error)
    		{
    			return false;
    		}
    	}
    	return false;
    }
    
    public function hasServiceMechanic ():Object
    {
    	if (_data)
    	{
    		try
    		{
    			return _data.team.mechanic;
    		}
    		catch (er:Error)
    		{
    			return false;
    		}
    	}
    	return false;
    }
    
    public function hasServiceTuningMaster ():Object
    {
    	if (_data)
    	{
    		try
    		{
    			return _data.team.appearance;
    		}
    		catch (er:Error)
    		{
    			return false;
    		}
    	}
    	return false;
    }

    kyzi007, 03 Февраля 2012

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

    +161

    1. 1
    while (!$db->query("INSERT INTO lots (lot_num) VALUES (".($unicnum=rand(1,99999)).")"));

    Проверка и создание уникального рандомного идентификатора

    dancebass, 17 Января 2012

    Комментарии (20)
  7. JavaScript / Говнокод #8612

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (!field.parentElement.childNodes[0].checked)
    {
    getElementByFieldName("Original").parentNode.childNodes[0].disabled = true;
    getElementByFieldName("Duplicate").parentNode.childNodes[0].disabled = true;
    ...

    Далее идет ещё примерно 20 аналогичных обращений, аля parentNode.childNodes[0]
    Очень читабельный и понятный код! :)

    LexeY4eg, 23 Ноября 2011

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

    −120

    1. 1
    2. 2
    3. 3
    4. 4
    // в BudgetDataVO.as
    public static const CONSOLIDATE_DATA:int = 3;	// when consolidated view is open
    // в другом месте:
    var firstIndex:int = type == BudgetDataVO.CONSOLIDATE_DATA ? -1 : 0;

    Все тот же Сан Диего.

    wvxvw, 08 Ноября 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    ..... Всякий HTML .....
    <?php echo "<div class='divfilter'>"; ?> 
    <?php echo "Пользователь: " ;?>
    <?php echo CHtml::dropDownList('id_member',$id_member, $members);  ?>
    <?php echo "</div>"; ?>
     ..... Всякий HTML .....

    Доделываю проект на Yii Framework, за предыдущим программистом, в одно их view заметил ))

    Igogo, 03 Ноября 2011

    Комментарии (20)
  10. PHP / Говнокод #8380

    +154

    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
    function getDirName($artistId)
        {
            $dirName = 1;
            $startNumber = 500;
            $result = false;
    
            while(!$result) {
                if ($artistId <= $startNumber) {
                    $result = true;
                }
                else {
                    $dirName++;
                    $startNumber += 500;
                }
            }
    
            return $dirName;
        }

    Весь прикол такой, что фотки на сервере лежат по 500 штук и зная id артиста можно узнать в какой из директории лежит его фотка. Вместо того чтобы написать, что то типа - $dirName = round($artistId / 500); я выдумал вот такую несуразицу :)

    dev6alexander, 01 Ноября 2011

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

    +133

    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
    /* ... */
    /**************************************************************************************
      cpu_information () parse /proc/cpuinfo to get information about CPU 
     **************************************************************************************/
    int cpu_information (data* user_data, int pos)
    {
      FILE *cpufp/* /proc/cpuinfo */ /*, *sysfs_max_cpu_freq_fp  /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq */;
       
      char* ch = (char*)malloc (MAXLEN);
      char* line = (char*)malloc (MAXLEN);
      char* buf = (char*)malloc (MAXLEN);
      
      GtkTreeIter iter[2];
      // int y = 0;
      if ((cpufp = fopen(CPU_INFORMATION_FILE, "r")) == NULL)
        printf ("%s\n", "Error opening /proc/cpuinfo");
    
      while (fgets (ch, MAXLEN, cpufp) != NULL) 
      {
        if (!strncmp (ch, "processor", 9)) 
        {
          sscanf (ch, "%*s %*s %s", line);
          strcpy (buf, "CPU");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[0],NULL, pos, 0, buf, 1, line, -1);
        } else if (!strncmp(ch, "vendor_id", 9))
        {
          sscanf(ch,"%*s %*s %s", line);
          strcpy (buf, "Processor type:");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1); 
        } else if (!strncmp(ch, "model name", 10))
        {
          strcpy(buf, "Model name");
          ch[strlen(ch)-1] = '\0'; //delete '\n' symbol from the end of string
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, &ch[13], -1);
        } else if (!strncmp(ch, "cpu MHz", 7))
        {
          int curr_cpu_freq;
          sscanf(ch, "%*s %*s %*s %d\n", &curr_cpu_freq);
          sprintf(line, "%d", curr_cpu_freq);
          strcpy (buf, "Current Processor Speed in MHz");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line,-1);
          /*
    	 Begin parsing /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq 
    	 
          sprintf (sysfs_max_cpu_freq_path, SYSFS_CPU_MAX_FREQ_FORMAT_STRING, y);
          if ((sysfs_max_cpu_freq_fp = fopen (sysfs_max_cpu_freq_path, "r")) == NULL) {
        	  printf("%s %s\n", "Error opening",  sysfs_max_cpu_freq_path);
          }
          while (fgets (line, MAXLEN, sysfs_max_cpu_freq_fp) != NULL)
          {
    	sscanf (line, "%d", &max_cpu_freq);
    	sprintf (line, "%d", max_cpu_freq/1000);
    	strcpy (buf, "Max Processor Speed in MHz");
    	gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[2],&iter[1], pos, 0, buf, 1, line,-1);
          }
          y++;
          
    	 End parsing 
           
          fclose (sysfs_max_cpu_freq_fp);*/
        }  else if (!strncmp(ch, "cache size", 10))
        {
          sscanf(ch, "%*s %*s %*s %s", line);
          strcpy (buf, "Processor cache size");
          strcat (line, " KB");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
    
        } else if (!strncmp(ch, "bogomips", 8)) 
        {
          sscanf(ch, "%*s %*s %s", line);
          strcpy (buf, "Processor speed in Bogomips");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
          cpu_temperature (user_data,&iter[0], pos); //get CPU temperature.
        }
        pos++;
      }
    
      free (buf);
      free (line);
      free (ch);
      //free (sysfs_max_cpu_freq_path);
      fclose (cpufp);
      return 0;
    }
    /* ... */

    По просьбам трудящихся http://govnokod.ru/7979#comment116436

    По коду:
    1) хорошо бы проверять, что попытался выделить;
    2) ошибка произошла успешно — начинаем парсить...;
    3) для решения таких задач стоит обратить своё внимание на, например, PyGTK.

    P.S. Если уж совсем не в мочь и к строкам так тянет,
    то допилите под себя LiteC, у Г.Шилдта есть что подсмотреть.

    sayidandrtfm, 31 Октября 2011

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