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

    +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
    //retrive the weather file
        QProcess* process = new QProcess(this);
        QString command = "wget -O " + QDir::homePath() + "/.weather.xml http://weather.yahooapis.com/forecastrss?p=" + zip;
    
        if(tempType == "C")
        {
           command.append("&u=c");
        }
        
        process->start(command);
        process->waitForFinished();
        delete process;

    Учитесь писать переносимый код!

    Sauron, 12 Августа 2009

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

    +13

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    __inline BOOL IsNumeric(LPTSTR lpsBuf)
    {
     int i, nSize = _tcslen(lpsBuf);
     for (i = 0; i < nSize; i++)
      if ((lpsBuf[i] < _T('0')) || (lpsBuf[i] > _T('9')))
       return (FALSE);
     return (TRUE);
    }

    Серъёзный алгоритм.

    Exhumer, 12 Августа 2009

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

    +17

    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
    std::string sError = "";
    try
    {
       fIn = fopen(cszFileName, "rb");
       if (fIn == 0)
       {
         sError = "Can not open file: ";
         sError += cszFileName;
         throw std::string("");
       }
    
       if (!ParseFile(fIn, pLookup))
       {
         sError = "Bad file format. File: ";
         sError += cszFileName;
         throw std::string("");
       }
    
       sError = "";
       throw std::string("");
    }
    catch (std::string& e)
    {
       if (fIn != 0)
       {
          fclose(fIn);
          fIn = NULL;
       }
       if (sError.length() != 0)
       {
          throw std::exception(sError.c_str());
       }
    }

    Там же нашел еще более шикарное продолжение гавнокода http://govnokod.ru/1459

    lugal, 12 Августа 2009

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

    +18.3

    1. 1
    2. 2
    3. 3
    4. 4
    while(0<1)
    {
      ...
    }

    В универе встречал такой вот бесконечный цикл

    shurikroger, 12 Августа 2009

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

    +34

    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
    void dump_indexes(map<int,stride_slices> picks, ofstream &f);
    {
      f<<"# full size: "<<picks.size()<<endl;
      for(map<int, stride_slices>::iterator
    	p=picks.begin(); p!=picks.end(); ++p)
        {
          f<<"## "
           <<p->first<<"'st stride slices count: "
           <<p->second.size()<<endl;
          
          for(stride_slices::iterator
    	    pp=p->second.begin(); pp!=p->second.end(); ++pp)
    	{
    	  f<<"### "
    	   << p->first<<"'st stride, "
    	   <<pp->first<<"'st slice size: "
    	   <<pp->second.size()<<endl;
    	  for(max_slice::iterator
    		ppp=pp->second.begin(); ppp!=pp->second.end(); ++ppp)
    	    {
    	      f<<"#### "
    	       <<p->first<<"'st stride, "
    	       <<pp->first<<"'st slice, "
    	       <<ppp->first<<"'st chunk size:"
    	       <<ppp->second.size()<<endl;
    	      
    	      for(max_chunk::iterator
    		    pppp=ppp->second.begin(); pppp!=ppp->second.end(); ++pppp)
    		f<<"       "
    		 <<p->first<<" "
    		 <<pp->first<<" "
    		 <<ppp->first<<" "
    		 <<pppp->first<<" : "
    		 <<pppp->second<<endl;	
    	    }
    	}
        }
    }

    а как нормально просмотреть кучу вложенных контейнеров?

    Biburath, 11 Августа 2009

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

    +33.2

    1. 1
    cStaticObject * CreateStaticObject	( obj_id_t object_id, mesh_id_t mesh_id, material_id_t material_id, int32_t coord_x, int32_t coord_y, int32_t coord_z, int32_t angle_azimuth, int32_t angle_zenith, int32_t angle_longitudinal, uint32_t size_x, uint32_t size_y, uint32_t size_z, uint16_t flags );

    stup, 11 Августа 2009

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

    +46.3

    1. 1
    delete ptr + int(ptr=0);

    Освобождение памяти и обнуление указателя.

    k06a, 11 Августа 2009

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

    +24.3

    1. 1
    2. 2
    3. 3
    bool TimeSpan::operator != (const TimeSpan & tvalue) const {
    	return *this != tvalue;
    }

    Веселый код в одной либе. То то я удивился, откуда у меня stack owerflow там где его быть не может.

    Автор виддимо хотел написать !(*this == tvalue) но протупил. =)

    guest, 09 Августа 2009

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

    +111.7

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    typedef struct pl
    {
    int speed;
    double time;
    char cname[25];
    }player;
    
    int cni;//countries number
    static double disti;//distance of road
    player *bpll;
    
    class country
    {
    public:
    //    country();
    //  country(country& cnr);
        void setinfo();
        char name[25];
        int pn;
        int sp;
        player *cpl;
        player *bpl;
        void getname(char *name);
        void findbestplayer(int pp);
        void sortplayers();
        ~country();
    };
    
    void country::setinfo()
    {
        static char nm[255];
        printf("Enter country name\n");
        gets(nm);
        strcpy(name,nm);
        printf("Country name: %s\n",name);
        static char pnc[25];
        printf("Enter number of players: ");
        gets(pnc);
        pn=atoi(pnc);
        cpl=new player[pn];
        for(int i2=0;i2<pn;i2++)
        {
        int spd;
        static char spdc[10];
        printf("Enter speed of player %d:",i2+1);
        gets(spdc);
        spd=atoi(spdc);
        cpl[i2].speed=spd;
        cpl[i2].time=disti/spd;
        memset(&cpl[i2].cname,0x20,25);
        strcpy(cpl[i2].cname,name);
        printf("Player time %f\n",cpl[i2].time);
        };
    return;
    };
    country::~country()
    {
        delete []cpl;
        delete []bpl;
    };
    
    void country::findbestplayer(int pp)
    {
    int min=0;
    bpl=new player;
    for(int i=1;i<pn;i++)
    {
        if(cpl[i].time<cpl[min].time){
        min=i;
        };
    bpl=&cpl[min];
    };
    return;
    };
    
    int compare (player * arg1, player * arg2);
    
    int main(int argc,char *argv[])
    {
       static char cn[10];
       static char dist[10];
       printf("Enter distance\n");
       gets(dist);
       disti=atoi(dist);
       printf("Enter number of countries\n");
       gets(cn);
       cni=atoi(cn);
       country c1[cni];
       bpll=new player[cni];
       for(int i=0;i<cni;i++)
       {
        c1[i].setinfo();
        c1[i].findbestplayer(c1[i].pn);
        printf("best time %f\n",c1[i].bpl->time);
        bpll[i].speed=c1[i].bpl->speed;
        bpll[i].time=c1[i].bpl->time;

    Задача для олимпиады для подсчёта занятых мест по времени и скорости, каждого спортсмена, предыдущее но правильно работающее.

    guest, 08 Августа 2009

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

    +123

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    typedef struct pl
    {
    int speed;
    double time;
    }player;
    
    int cni;//countries number
    static double disti;//distance of road
    
    class stack
    {
    public:
    	stack(int i)
    	{
    	ael=new int[i];
    	sp=0;
    	};
    	int pop(void);
    	void push(int el);
    	int sp;
    private:
    	int *ael;
    };
    
    class country : public stack
    {
    public:
        country();
        void setinfo();
        char name[25];
        int pn;
        int sp;
        player *cpl;
        player *bpl;
        void getname(char *name);
        player* findbestplayer();
        void sortplayers();
        ~country();
    };
    country::country():stack(cni)
    {
    };
    
    void country::setinfo()
    {
        static char nm[255];
        printf("Enter country name\n");
        gets(nm);
        strcpy(name,nm);
        printf("Country name: %s\n",name);
        static char pnc[25];
        printf("Enter number of players: ");
        gets(pnc);
        pn=atoi(pnc);
        cpl=new player[pn];
        for(int i2=0;i2<pn;i2++)
    	{
    	int spd;
    	static char spdc[10];
    	printf("Enter speed of player %d:",i2+1);
    	gets(spdc);
    	spd=atoi(spdc);
    	cpl[i2].speed=spd;
    	cpl[i2].time=disti/spd;
    	printf("Player time %f\n",cpl[i2].time);
    	};
    return;
    };
    country::~country()
    {
        delete []cpl;
        delete []bpl;
    };
    
    player* country::findbestplayer()
    {
    int bpl2=0;
    for(int i3=1;i3<pn;i3++)
    {
        if(cpl[i3].time<cpl[bpl2].time){
        bpl2=i3;
    };
    *bpl=cpl[bpl2];
    return &cpl[bpl2];
    };
    
    };
    
    int getspeed(struct pl pll);
    void sort(country *cnt);
    
    int main(int argc,char *argv[])
    {
       static char cn[10];
       static char dist[10];
       printf("Enter distance\n");

    guest, 07 Августа 2009

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