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

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

    +161

    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
    //main.cpp
    #include "head.h"
    int main()
    {
    //fcii.cpp
    #include "head.h"
    void odin (vector<Zapis> &mas)
    {
    Zapis buf;
    cout<<"Введите номер УДК: ";
    cin>>buf.id;
    cout<<"Введите фамилию и инициалы автора: ";
    cin>>buf.fio;
    cout<<"Введите название книги: ";
    cin>>buf.nazv;
    cout<<"Введите год издания: ";
    cin>>buf.god;
    cout<<"Введите количество экземпляров: ";
    cin>>buf.kol;
    mas.resize(mas.size()+1,buf);
    vivod (mas);
    }
    void dva (vector<Zapis> &mas)
    {
    char udk[4];
    cout<<"Введите УДК книги, которую необходимо удалить: ";
    cin>>udk;
    int flag=1;
    int k=0;
    for (vector<Zapis>::iterator i=mas.begin();i!=mas.end();i++)
    {
    flag=1;
    if (strlen(udk)==strlen(mas[k].id))
    for (int j=0;udk[j]!=0;j++)
    if (udk[j]!=mas[k].id[j])
    flag=0;
    if (flag==1)
    {
    mas.erase(i);
    flag=-1;
    break;
    }
    k++;
    }
    
    if (flag!=-1)
    {
    cout<<endl<<"Книги с данным УДК не существует"<<endl;
    }
    else vivod(mas);
    }
    void tri(vector<Zapis> &mas)
    {
    vector<int> mas_buf(mas.size());
    for (int i=0;i<mas.size();i++)
    mas_buf[i]=mas[i].god;
    sort(mas_buf.begin(),mas_buf.end()) ;
    for (int i=0;i<mas.size();i++)
    mas[i].god=mas_buf[i];
    vivod(mas);
    }
    int zapros (vector<Zapis> &mas)
    {
    int otvet;
    cout<<endl<<"Если вы хотите добавить данные о книгах - нажмите 1;"<<endl;
    cout<<"Если вы хотите удалить данные о списываемых книгах - нажмите 2;"<<endl;
    cout<<"Если вы хотите упорядочить книги по годам издания - нажмите 3;"<<endl;
    cout<<"Если вы хотите завершить работу программы - нажмите 0."<<endl;
    cin>>otvet;
    
    switch (otvet)
    {
    case 0: {return 0;}
    case 1: {
    odin(mas);
    zapros(mas);break;
    }

    Взято отсюда: http://programmersforum.ru/forumdisplay.php?f=14

    elenbert, 14 Апреля 2011

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    $dateFrom_array = explode('-', $_REQUEST['intervalFrom']);
    $dateUnix = mktime(0, 0, 0, $dateFrom_array[1], $dateFrom_array[2], $dateFrom_array[0]);
    $dateUnix -= 60 * 60 * 24 * 30 * 2; // - 2 месяца
    $dateFrom = date("Y-m-d", $dateUnix);

    goliath, 11 Апреля 2011

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

    +162

    1. 1
    2. 2
    foreach(split(',', '101,102,150,1351,2135,22153,351,15321,5351,235') as $key => $val)
    	$tmparray[] = $val;

    разбиваем строку в массив )))

    pes, 05 Апреля 2011

    Комментарии (14)
  5. C# / Говнокод #6099

    +117

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Caeser_method
    {
        class Program
        {
            static void Main(string[] args)
            {
                int n = 3;
                Console.Write("Input string to encoding: ");
                string input = Console.ReadLine();
                Csr enc = new Csr(n,input);
               // Csr dec;
                enc.encrypt();
                Console.WriteLine(enc);
               // dec = new Csr(n, input);
                enc.decrypt();
                
                Console.WriteLine(enc);
                Console.ReadLine();
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Caeser_method
    {
        class Csr
        {
            public int n;
            public string phraze,outputphr;
            public Csr(int n, string phraze) 
            {
                this.n = n;
                this.phraze = phraze;
                this.outputphr = "";
            }
    
            
            public void encrypt() 
            {
                foreach (char c in this.phraze)
                    if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
                    {
                        if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
                                                                          (c + this.n > 'Z' ? ('A' + ((c -'Z'  + (this.n - 1)))) : (c + this.n)) :
                                                                          (c + this.n > 'z' ? ('a' + ((c - 'z' + (this.n - 1)))) : (c + this.n)));
                        else this.outputphr += c;
                    }
                    else
                    {
                        if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
                                                                          (c + this.n > 'Я' ? ('А' + ((c - 'Я' + (this.n - 1)))) : (c + this.n)) :
                                                                          (c + this.n > 'я' ? ('а' + ((c - 'я' + (this.n - 1)))) : (c + this.n)));
                        else this.outputphr += c;
                    }
            }
    
    
            public void decrypt()
            {
                this.phraze = this.outputphr;
                this.outputphr = "";
                foreach (char c in this.phraze)
                    if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
                    {
                        if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
                                                                          (c - this.n < 'A' ? ('Z' - (('A' - c + (this.n - 1)))) : (c - this.n)) :
                                                                          (c - this.n < 'a' ? ('z' - (('a' - c + (this.n - 1)))) : (c - this.n)));
                        else this.outputphr += c;
                    }
                    else
                    {
                        if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
                                                                          (c - this.n < 'А' ? ('Я' - (('А' - c + (this.n - 1)))) : (c - this.n)) :
                                                                          (c - this.n < 'а' ? ('я' - (('а' - c + (this.n - 1)))) : (c - this.n)));
                        else this.outputphr += c;
                    }
            }
    
            public override string ToString()
            {
                return string.Format("Encoded string: {0}",this.outputphr);
            }
    
        }
    }

    Реализация шифрования методом Цезаря

    rybaki, 27 Марта 2011

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

    +158

    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
    class Query {
      protected $baseTable;
      protected $baseTableAlias;
      protected $whereGroup;
    
      protected $joins = array();
      protected $fields = array();
    
      protected $executed = FALSE;
      protected $resource = NULL;
    
    
      function __construct($base_table = 'node', $alias = 'n') {
        $this->whereGroup = new QueryWhereGroup();
        $this->baseTable = $base_table;
        $this->baseTableAlias = empty($alias) ? $base_table : $alias;
      }
    
      function select($fields) {
        settype($fields, 'array');
        foreach ($fields as $alias => $field) {
          if (is_numeric($alias)) {
            $this->fields[] = $field;
          }
          else {
            $this->fields[$alias] = "$field as $alias";
          }
        }
    
        return $this;
      }
    
      /**
       * @param QueryWhereGroup $whereGroup
       * @return Query
       */
      function where($whereGroup) {
        call_user_func_array(array($this->whereGroup, 'cond'), func_get_args());
        return $this;
      }
    
      function createWhereGroup() {
        return new QueryWhereGroup();
      }
    
      function join($table, $alias = NULL, $condition, $join_type = 'INNER') {
        if (!$alias) {
          $alias = $table;
        }
    
        if (is_array($condition)) {
          $condition = 'USING ('. join(', ', $condition) .')';
        }
        if (!preg_match('/^ON|USING/i', $condition)) {
          $condition = 'ON '. $condition;
        }
    
        $this->joins[$alias] = "$join_type JOIN $table $alias $condition";
        return $this;
      }
    
      function compile() {
        $select_fields = join(', ', array_unique($this->fields));
        $joins_list = join("\n", $this->joins);
        $where_conditions = $this->whereGroup->compile();
    
        if (!empty($where_conditions)) {
          $where_conditions = 'WHERE '. $where_conditions;
        }
    
        return "SELECT $select_fields FROM {{$this->baseTable}} {$this->baseTableAlias} \n $joins_list $where_conditions";
      }
    
      function args() {
        return $this->whereGroup->args;
      }
    
      function execute() {
        return db_query($this->compile(), $this->args());
      }
    
      function fetchAll() {
        $res = $this->execute();
        while($row = db_fetch_object($res)) {
          $rows[] = $row;
        }
        return $rows;
      }
    }

    построитель запросов (drupal 6)
    wheregroup здесь http://govnokod.ru/6076

    vectoroc, 23 Марта 2011

    Комментарии (14)
  7. Java / Говнокод #6069

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    top = width / 2d;
    bottom = width / 2d;
    left = height / 2d;
    right = height / 2d;

    Из-за данного участка кода было убито очень много нервова

    AngryBobby, 23 Марта 2011

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

    +168

    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
    #include <iostream>
    using namespace std;
    void main()
    {
        char U='#';
    int K;
        _asm
        {
            mov eax, 0
            mov al, U
            mov K,eax
        }
        cout<<K<<endl;
    }

    "Получение десятичного представления числа". C wasm.ru

    rat4, 18 Марта 2011

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

    +167

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    PopupWindow* GameLocations::getCurrentPopup()
    {
    	if(m_curPopup != nullptr && m_curPopup->needsClose())
    	{
    		m_curPopup->onClose();
    		m_curPopup = nullptr;
    		m_walker->BeginWalk(m_graph->getClosestNode(m_currentLocationId));
    	}
    	return m_curPopup;
    }

    Kirinyale, 18 Марта 2011

    Комментарии (14)
  10. SQL / Говнокод #6000

    −170

    1. 1
    SELECT 6000 FROM GETS

    qbasic, 16 Марта 2011

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

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function formatSpeedBits(speed) {
    	// format speed in bits/sec, input: bytes/sec
    	if (speed < 125000) return Math.round(speed / 125) + " Kbps";
    	if (speed < 125000000) return Math.round(speed / 1250)/100 + " Mbps";
    	// else
    	return Math.round(speed / 1250000)/100 + " Gbps";  // wow!
    }

    JS в интерфейсе прошивки dd-wrt. Не совсе говнокод.

    danilissimus, 04 Марта 2011

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