Кресты / Говнокод #1355 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  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 guest, (Updated )

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

Кресты / Говнокод #1353 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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 guest, (Updated )

Комментарии (3, +3)

Кресты / Говнокод #1341 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  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 guest, (Updated )

Комментарии (3, +3)

Кресты / Говнокод #1336 Ссылка на оригинал

0

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

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

guest guest, (Updated )

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

Кресты / Говнокод #1332 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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 guest, (Updated )

Комментарии (5, +5)

Кресты / Говнокод #1308 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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 guest, (Updated )

Комментарии (3, +3)

Кресты / Говнокод #1301 Ссылка на оригинал

0

  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 guest, (Updated )

Комментарии (23, +23)

Кресты / Говнокод #1287 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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 guest, (Updated )

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