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

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

    +108

    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
    ...
    var
     fileName  :string;                // имя файла
     mes       :string;                // текст мессаги
     capt      :string;                // заголовок мессаги
     f         :thandle;
     fils      :integer;
     BytesRead :D WORD;
     c         :byte;
    begin
     writeln('enter filename:');      // просим ввести имя файла
     readln(fileName);                // в fileName заносим имя файла
     if not fileexists(fileName) then // если он несуществует
      begin
      writeln('file not found :( ');   // виводит предупреждение
      readln;
      exit;                           // закриваем прогу
      end;
     writeln('');                              // просим ввесли текст мессаги
     writeln('enter message text (max 10):');  // максмальна длина 10 символов(так как в Project1.exe для нее зарезирвировано 10 байт) потому что длина HelloWorld=10
     readln(mes);
     writeln('');                                 // просим ввести заголовок мессаги
     writeln('enter message caption (max 10):');  // опять максимальная длина 10 символов
     readln(capt);
    
     f:=fileopen(fileName,fmOpenReadWrite);  // откриваем fileName
     fils:=Windows.GetFileSize(f,nil);       // получаем размер
     writeln('size = '+inttostr(fils)+'b');  // виводим размер
    
     // патчим байти для мессаги
     // $2848,$2849,$284A,$284B,$284C,$284D,$284E,$284F,$2850,$2851
     c:=ord(char(pchar(mes[1])));             // патчим первий байт
     SetFilePointer(f, $2848, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(mes[2])));             // патчим второй (2) байт
     SetFilePointer(f, $2849, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(mes[3])));             // патчим 3 байт
     SetFilePointer(f, $284A, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(mes[4])));             // патчим 4 байт;
     SetFilePointer(f, $284B, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(mes[5])));             // патчим 5 байт
     SetFilePointer(f, $284C, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(mes[6])));             // патчим 6 байт
     SetFilePointer(f, $284D, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(mes[7])));             // патчим 7 байт
     SetFilePointer(f, $284E, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(mes[8])));             // патчим 8 байт
     SetFilePointer(f, $284F, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(mes[9])));             // патчим 9 байт
     SetFilePointer(f, $2850, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(mes[10])));             // патчим 10 байт
     SetFilePointer(f, $2851, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     // патчим байти для заголовка мессаги
     // адреса с $283C до $2845
     c:=ord(char(pchar(capt[1])));            // патчим первий байт
     SetFilePointer(f, $283C, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(capt[2])));            // патчим второй байт
     SetFilePointer(f, $283D, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(capt[3])));            // третий символ и так дальше
     SetFilePointer(f, $283E, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(capt[4])));
     SetFilePointer(f, $283F, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    
     c:=ord(char(pchar(capt[5])));
     SetFilePointer(f, $2840, nil, 0);
     WriteFile(f, c, SizeOf(c), BytesRead, nil);
    ...

    Где-то нашёл =(

    BlincAttack, 21 Июля 2010

    Комментарии (29)
  3. C# / Говнокод #3679

    +108

    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
    class Matrix
    {
        double[,] matrix;
        int rows, columns;
    
        // Не вызывается до закрытия приложения
        ~Matrix()
        {
            Console.WriteLine("Finalize");
        }
    
        public Matrix(int sizeA, int sizeB)
        {
            rows = sizeA;
            columns = sizeB;
            matrix = new double[sizeA, sizeB];
        }
    
        // Индексатор для установки/получения элементов внутреннего массива
        public double this[int i, int j]
        {
            set { matrix[i,j] = value; }
            get { return matrix[i,j]; }
        }
    
        // Возвращает число строк в матрице
        public int Rows
        {
            get { return rows; }
        }
    
        // Возвращает число столбцов в матрице
        public int Columns
        {
            get { return rows; }
        }
    
    }

    Нашёл в статье из MSDN'а

    FMB, 10 Июля 2010

    Комментарии (31)
  4. C# / Говнокод #545

    +108

    1. 1
    return ((int)(Counter / 2) != Counter / 2.00 && Counter != 0);

    Не садил, так не ломай - у нас сегодня первомай :D
    Оставили в продакшене, чисто для музейной ценности :D

    guest, 13 Февраля 2009

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

    +107.9

    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
    if l<9
     then
      if r<10
       then
        s:= inttostr(l)
       else
        s:= '10'
     else
      if l<99
       then
        if r<100
         then
          s:= inttostr(l)
         else
          s:= '100'
       else
        if l<999
         then
          if r<1000
           then
            s:= inttostr(l)
           else
            s:= '1000'
         else
          if l<9999
           then
            if r<10000
             then
              s:= inttostr(l)
             else
              s:= '10000'
           else
            if l<99999
             then
              if r<100000
               then
                s:= inttostr(l)
               else
                s:= '100000'
             else
              if l<999999
               then
                if r<1000000
                 then
                  s:= inttostr(l)
                 else
                  s:= '1000000'
               else
                if l<9999999
                 then
                  if r<10000000
                   then
                    s:= inttostr(l)
                   else
                  s:= '10000000'
                 else
                  if l<99999999
                   then
                    if r<100000000
                     then
                      s:= inttostr(l)
                     else
                      s:= '100000000'
                   else
                    if l<999999999
                     then
                      if r<1000000000
                       then
                        s:= inttostr(l)
                       else
                        s:= '1000000000';

    Нашёл в своём решении какой-то олимпиадной задачи. Долго пытался вспомнить, в каком состоянии был...

    Сан Саныч, 05 Октября 2009

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

    +107.8

    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
    string status = ProcessData("db1");
                if (status == "ERROR") goto ErrorOccured;
                status = ProcessData("db2");
                if (status == "ERROR") goto ErrorOccured;
                status = ProcessData("db3");
                if (status == "ERROR") goto ErrorOccured;
                if (status == "OK") goto NoError;
    
                ErrorOccured:
                    tran.Rollback();
                    return status;
                NoError:
                    tran.Commit()

    пятница однако... :)

    вот "обнаружил" кодЪ (не забываем, что C#)::

    чем товарищЪ думал, трудно понять...

    guest, 27 Февраля 2009

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

    +107.5

    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
    /// <summary>
            /// Check if this char is digit
            /// </summary>
            /// <param name="symbol">Some char</param>
            /// <returns>True if is digit</returns>
            private static bool IsDigit(char symbol)
            {
                List<char> digits = new List<char>();
                digits.Add('0');
                digits.Add('1');
                digits.Add('2');
                digits.Add('3');
                digits.Add('4');
                digits.Add('5');
                digits.Add('6');
                digits.Add('7');
                digits.Add('8');
                digits.Add('9');
                return digits.Contains(symbol);
            }

    так сказать код от велосипедиста, сделал свой IsDigit() хотя уже есть char.IsDigit()

    sv219, 13 Августа 2009

    Комментарии (259)
  8. C# / Говнокод #2960

    +107.4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    DirectoryEntry en = this.InitDirectoryEntry(ADObject);
    
    try
    {                   
         en.Parent.Children.Remove(en);
    }
    catch (Exception ex)
    {
               //??????????????????????????????
    }

    Удаление объекта в каталоге Active Directory

    dens, 08 Апреля 2010

    Комментарии (6)
  9. Pascal / Говнокод #2604

    +107.2

    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
    procedure TFormMoneyToBag.AMEditVirtualKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      Field : string;
      Value : integer;
    begin
      if (Key = 16) or (Key = 13) then begin
        with ADOHardCash.FieldByName('Dengi') do begin
          if AsString = '500 грн' then Field := '[500hrn]'
          else if AsString = '200 грн' then Field := '[200hrn]'
               else if AsString = '100 грн' then Field := '[100hrn]'
                    else if AsString = '50 грн' then Field := '[50hrn]'
                         else if AsString = '20 грн' then Field := '[20hrn]'
                              else if AsString = '10 грн' then Field := '[10hrn]'
                                   else if AsString = '5 грн' then Field := '[5hrn]'
                                        else if AsString = '2 грн' then Field := '[2hrn]'
                                             else if AsString = '1 грн' then Field := '[1hrn]'
                                                  else if AsString = '1 грн монета' then Field := '[1hrnCoin]'
                                                       else if AsString = '50 коп' then Field := '[50kopCoin]'
                                                            else if AsString = '25 коп' then Field := '[25kopCoin]'
                                                                 else if AsString = '10 коп' then Field := '[10kopCoin]'
                                                                      else if AsString = '5 коп' then Field := '[5kopCoin]'
                                                                           else if AsString = '2 коп' then Field := '[2kopCoin]'
                                                                                else if AsString = '1 коп' then Field := '[1kopCoin]'
        end;
    
        UpdateIncassationCurrentValue.Parameters.ParamByName('@IncassationId').Value := IncassationId;
        UpdateIncassationCurrentValue.Parameters.ParamByName('@Field').Value := Field;
        if AMEditVirtual.Text = '' then Value := 0 else Value := StrToInt(AMEditVirtual.Text);
        UpdateIncassationCurrentValue.Parameters.ParamByName('@Value').Value := Value;
        ExecStoredProc(UpdateIncassationCurrentValue);
    
        RequeryADO(ADOHardCash);
        RequeryADO(ADOCashDeskInfo);
        ButtonStatus;
        AMEditVirtual.Visible := false;
      end;
    end;

    Сие Чудо техники заполняет параметры для выполнения хранимой процедуры на сервере.
    Написал Большой Мудила, хотя в целом он хороший человек.

    cruelwizard, 12 Февраля 2010

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

    +107

    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
    var a : int64;
     
    begin
      assign(input, 'input.txt'); reset(input);
      assign(output, 'output.txt'); rewrite(output);
      read(a);
      if a=25 then write ('2.7182818284590452353602875');
      if a=24 then write ('2.718281828459045235360288');
      if a=23 then write ('2.71828182845904523536029');
      if a=22 then write ('2.7182818284590452353603');
      if a=21 then write ('2.718281828459045235360');
      if a=20 then write ('2.71828182845904523536');
      if a=19 then write ('2.7182818284590452354');
      if a=18 then write ('2.718281828459045235');
      if a=17 then write ('2.71828182845904524');
      if a=16 then write ('2.7182818284590452');
      if a=15 then write ('2.718281828459045');
      if a=14 then write ('2.71828182845905');
      if a=13 then write ('2.7182818284590');
      if a=12 then write ('2.718281828459');
      if a=11 then write ('2.71828182846');
      if a=10 then write ('2.7182818285');
      if a=9 then write ('2.718281828');
      if a=8 then write ('2.71828183');
      if a=7 then write ('2.7182818');
      if a=6 then write ('2.718282');
      if a=5 then write ('2.71828');
      if a=4 then write ('2.7183');
      if a=3 then write ('2.718');
      if a=2 then write ('2.72');
      if a=1 then write ('2.7');
      if a=0 then write ('3') 
    end.

    Вывод числа e с заданной точностью

    AndreyZ, 04 Января 2015

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

    +107

    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
    public class Visit 
    {
    	public DateTime Start {get; set;}
    	public DateTime Finish {get; set;}
    }
    
    public bool IsConflict(Visit a, Visit b)
    {
    	var s = GetArray(a);
    	var s2 = GetArray(b);
    	return Compare(s,s2);
    }
    
    private List<string> GetArray(Visit visit)
    {
    	var list = new List<string>();
    	while (visit.Start < visit.Finish)
    	{ 
    	  list.Add(visit.Finish.ToString()); // в строках!
    	  visit.Finish -= TimeSpan.FromMinutes(1); // по 1й минуте!!!
    	}
    	return list;
    }
    private bool Compare(List<string> list1, List<string> list2)
    {
    
    	foreach (var s in list1)
    	{
    		if (list2.Any(x => x == s))
    		{
    			return false;
    		}
    	}
    	return true;
    }

    Основная здесь функция, предназначенная для вызова, - IsConflict(Visit a, Visit b)
    Она должна проверять, пересекаются ли меджу собой два промежутка времени.
    Вот такая проверка со сложностью O(n*n) , где n - кол-во минут в промежутках времени.

    kasitan, 18 Сентября 2013

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