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

    +131.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    class Par_host_port
    {
    private:
            std::string vdata;
    public:
    //...
            char* get () { return (char*)vdata.c_str (); }
    };

    char const* превращается... Превращается char const*... В char*!

    guest, 15 Июля 2009

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

    +153

    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
    void AddMatchDialog::doAction(QListWidget *list, QListWidget *playersList)
        {
        //prepare
        MatchStatistics *stats;
        QLabel *score;
        QStringList *s, *ch;
        static QStringList homeStart, homeChanges, awayStart, awayChanges;
        if (list == m_ui->lstHome) {
            stats = &m.home;
            s = &homeStart;
            ch = &homeChanges;
            score = m_ui->lblHomeScore;
        }
        else if (list == m_ui->lstAway) {
            stats = &m.away;
            s = &awayStart;
            ch = &awayChanges;
            score = m_ui->lblAwayScore;
        }
        else {return;}
        if (s->isEmpty() && ch->isEmpty()) {
            stats->goals = 0;
            foreach (Player p, stats->club.players) {
                if (stats->start.contains(p))
                    s->append(p.name);
                else
                    ch->append(p.name);
            }
    
        }
    
      //счетчик желтых карточек
     static QStringList yellowCarders;
            EventDialog *dlg = new EventDialog(this, *s, *ch);
            if (dlg->exec() == QDialog::Accepted) {
                QStringList data = dlg->getData();
                 QListWidgetItem *it = new QListWidgetItem(0);
    
                switch (QVariant (data.at(1)).toInt()) {
                    qDebug() << data.at(1);
                    case 5:
                    stats->golaedors.append(stats->club.getPlayer(data.at(0)));
                    it->setIcon(QIcon(":/images/images/ball.png"));
                    it->setText(data.at(0));
                    list->addItem(it);
                         stats->goals ++;
                    score->setText(QVariant(stats->goals).toString());
                    break;
                    case 1:
                    if (!yellowCarders.contains(data.at(0))) {
                    stats->yellowCards.append(stats->club.getPlayer(data.at(0)));
                    it->setIcon(QIcon(":/images/images/whistle.png"));
                    it->setText(data.at(0));
                    list->addItem(it);
                    yellowCarders.append(data.at(0));}
                    else {
                     stats->yellowCards.append(stats->club.getPlayer(data.at(0)));
                    stats->redCards.append(stats->club.getPlayer(data.at(0)));
                    it->setIcon(QIcon(":/images/images/cards.png"));
                    it->setText(data.at(0));
                    list->addItem(it);
                    s->removeAt(s->indexOf(data.at(0)));
                    playersList->clear();
                    playersList->addItems(*s);
                    yellowCarders.removeAt(yellowCarders.indexOf(data.at(0)));
    
                    }
                    break;
                    case 2:
                    stats->redCards.append(stats->club.getPlayer(data.at(0)));
                    it->setIcon(QIcon(":/images/images/cards.png"));
                    it->setText(data.at(0));
                    list->addItem(it);
                    s->removeAt(s->indexOf(data.at(0)));
                    playersList->clear();
                    playersList->addItems(*s);
                    break;
                    case 3:
                    stats->traumas.append(stats->club.getPlayer(data.at(0)));
                    it->setIcon(QIcon(":/images/images/boots.png"));
                    it->setText(data.at(0));
                    list->addItem(it);
                    break;
                    case 4:
                    {
                    Change change;
                    change.first = stats->club.getPlayer(data.at(0));
                    change.second = stats->club.getPlayer(data.at(2));
                    stats->changes.append(change);
                    //item
                    it->setIcon(QIcon (":/images/images/change.png"));
                    it->setText(data.at(0) + " ? " + data.at(2));
                    list->addItem(it);
                    //change!
                   s->removeAt(s->indexOf(data.at(0)));
                   ch->removeAt (ch->indexOf(data.at(2)));
                   s->append(data.at(2));  
                   playersList->clear();
                   playersList->addItems(*s);
            // ...

    Я сейчас пишу систему сбора статистики футбольных матчей.
    Немного кода :). ВНИМАНИЕ: это Qt

    guest, 10 Июля 2009

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

    +148

    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
    template<class T>
    T from_string(const std::string &str)
    {
        std::istringstream iss(str);
        T ret_val;
        iss>>ret_val;
        return ret_val;
    }
    
    template <class T>
    std::string to_string(T val)
    {
        std::ostringstream oss;
        oss<<val;
        return oss.str();
    }
    
    template<> inline
    double from_string<double>(const std::string &str)
    {
        return atof(str.c_str());
    }

    взято с http://forums.realcoding.net/lofiversion/index.php/t15556.html

    конвертация строки в число/числа в строку

    guest, 10 Июля 2009

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

    +139.5

    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 <iostream>
    #include <deque>
    #include <time.h>
    using namespace std;
    int arr[10][10] = {
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    #define SHIPS 1
    struct point{
         int x, y;
    };
    int num = -1, count = 0;
    deque<point> ship;
    int way[] = {0, 0, 0, 0};
    void step(){
    	for (int i = 0; i < 10; i++){
    		for (int j = 0; j < 10; j++)
    			cout << arr[i][j] << ' ' ;
    		cout << '\n';
    	}
    
    	
    	cout << '\n';
    	
         if (num == ship.size()){
    		 memset(way, 0, sizeof(way));
              while(!ship.empty()){
                   arr[ship.front().x + 1][ship.front().y] = 7;
                   arr[ship.front().x + 1][ship.front().y + 1] = 7;
                   arr[ship.front().x][ship.front().y + 1] = 7;
                   arr[ship.front().x + 1][ship.front().y - 1] = 7;
                   arr[ship.front().x - 1][ship.front().y + 1] = 7;
                   arr[ship.front().x - 1][ship.front().y - 1] = 7;
                   arr[ship.front().x][ship.front().y - 1] = 7;
                   arr[ship.front().x - 1][ship.front().y] = 7;
                   ship.pop_front();
              }
              count++;
              if (count == SHIPS) {
                   cout << "Win" << '\n';
                   exit(0);
              }
              cout << num  << " was killed" << '\n'; 
              num = -1;
         }
         int x, y;
         point tmp;
         if (ship.empty()){
              x = rand()%10;
              y = rand()%10;
              while (arr[x][y] == 7){
                   x = rand()%10;
                   y = rand()%10;
              }
              if (arr[x][y] != 0 && arr[x][y] != 7){
                   num = arr[x][y];
                   tmp.x = x;
                   tmp.y = y;
                   ship.push_front(tmp);
                   arr[x][y] = 7;
    			   if (x > 0) if (arr[x][y - 1] != 7) way[0] = 1;
    			   if (y > 0) if (arr[x - 1][y] != 7) way[1] = 1;
    			   if (x < 9) if (arr[x][y + 1] != 7) way[2] = 1;
    			   if (y < 9) if (arr[x + 1][y] != 7) way[3] = 1;
                   step();
              }else{
                   arr[x][y] = 7;
                   return;
              }
         }else{
    		  int t = rand()%4;
    		  while (way[t] == 0){
    			  t = rand()%4;
    		  }
    		  switch(t){
    			  case 0:
    				  x = ship.back().x;
                      y = ship.back().y - 1;
    				  if(arr[x][y] == num){
    					  way[1] = 0;
    					  way[3] = 0;
    					  tmp.x = x;
    					  tmp.y = y;
    					  ship.push_back(tmp);
    					  arr[x][y] = 7;
    					  step();
    				  }else{
    					  arr[x][y] = 7;
    					  way[0] = 0;
    					  return;
    				  }

    Морской бой

    guest, 08 Июля 2009

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

    +133.3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    setlocale(0,"");
    int x;
    cin >> x;
    if(x > 10 && x < 0)
    {
          cout << "Неверный множытель!" << endl;
    }
    else
    {
          //...
    }

    А, я ещё удивлялса, почемуже она работает не так как надо)))

    guest, 08 Июля 2009

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

    +149

    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
    //--------------------------------------------------------------------------------------------------------------------------------------------------
    //----------------------------------------------------------INCLUDES--------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------
    
    #include <stdio.h>
    #include <iostream>
    #include <conio.h>
    #include <windows.h>
    #include <time.h>
    #include <string.h>
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------DEFINES----------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------
    
    #define PI 3.14
    #define jmp(label) goto label
    #define snl printf("\n")
    #define	printl(str) printf(str);snl
    #define add(n0,n1) n0+n1
    #define sub(n0,n1) n0-n1
    #define mov(n0,n1) n0=n1
    #define rpl(n0,n1) int tmp; tmp=n0; n0=n1; n1=tmp
    #define Nothing void
    #define EverLoop(operator) while(true){operator;}
    
    //--------------------------------------------------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------NAMESPACES-------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------------------------------------------------------
    
    namespace ofn
    {
    	namespace Math
    	{
    		int PushedValue;
    
    		int factorial(int Num)
    		{
    			int res = 1;
    			for(int i=1;i<=Num;i++)
    			{
    				res = res * i;
    			}
    			return res;
    		}
    
    		bool mod(int Num,int module)
    		{
    			if(Num % module == 0) return true;
    			else return false;
    		}
    
    		void push(int value)
    		{
    			PushedValue = value;
    		}
    
    		int pop()
    		{
    			return PushedValue;
    		}
    	}
    
    	namespace Strings
    	{
    		char* Files(){return "Namespace \"Strings\" is empty!";}
    	}
    
    	namespace Files
    	{
    		char* Files(){return "Namespace \"Files\" is empty!";}
    	}
    }

    Вот нашол у себя на компе такой хеадер))))
    Делалса он тупо ради прикола...

    guest, 07 Июля 2009

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

    +150

    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
    _strlwr(buf);
    if(buf[0] == '\"') strcpy(buf, &(buf[1]));
    if(strstr(buf, "\""))
    {
    	if(strrchr(buf, '\\'))
    	{
    		if(strchr(strrchr(buf, '\\'), ' '))
    		{
    			*(strchr(strrchr(buf, '\\'), ' ')) = 0;
    		}
    	}
    	strncpy(szPath, buf, (DWORD)strstr(buf, "\"") - (DWORD)buf);
    	return 0;
    }
    else
    {
    	if(strrchr(buf, '\\'))
    	{
    		if(strchr(strrchr(buf, '\\'), ' '))
    		{
    			*(strchr(strrchr(buf, '\\'), ' ')) = 0;
    		}
    	}
    	strcpy(szPath, buf);
    	return 0;
    }

    Определение дефолтного браузера

    guest, 02 Июля 2009

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

    +1001.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    void get_tomorrow_date( struct timeval *date )
      {
        sleep( 86400 ); // 60 * 60 * 24
        gettimeofday( date, 0 );
      }

    На одном индусском форуме программистов задали вопрос: "Как вычислить завтрашнюю дату?".
    Ответ был шедевральным и уже разошёлся по всему миру:

    guest, 01 Июля 2009

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

    +54.9

    1. 1
    2. 2
    3. 3
    for( i = 0; i < 2; i++) {
    	if ((Result = AvCrpSignFile(iSession, szSrcFile, szDstFile, 0)) == AVCRPR_SUCCESS) break;
    }

    чтобы наверняка

    guest, 30 Июня 2009

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

    +89

    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
    #if __STDC_WANT_SECURE_LIB__
    _Check_return_opt_ _CRTIMP int __cdecl fscanf_s(_Inout_ FILE * _File, _In_z_ _Scanf_s_format_string_ const char * _Format, ...);
    #endif
    _Check_return_opt_ _CRTIMP int __cdecl _fscanf_s_l(_Inout_ FILE * _File, _In_z_ _Scanf_s_format_string_ const char * _Format, _In_opt_ _locale_t _Locale, ...);
    _Check_return_opt_ _CRTIMP int __cdecl fsetpos(_Inout_ FILE * _File, _In_ const fpos_t * _Pos);
    _Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE * _File, _In_ long _Offset, _In_ int _Origin);
    _Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE * _File);
    
    _Check_return_opt_ _CRTIMP int __cdecl _fseeki64(_Inout_ FILE * _File, _In_ __int64 _Offset, _In_ int _Origin);
    _Check_return_ _CRTIMP __int64 __cdecl _ftelli64(_Inout_ FILE * _File);
    
    _Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_count_x_(_Size*_Count) const void * _Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE * _File);
    _Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE * _File);
    _Check_return_ _CRTIMP int __cdecl getchar(void);
    _Check_return_ _CRTIMP int __cdecl _getmaxstdio(void);

    Говнокод из Вермонда

    guest, 30 Июня 2009

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