- 1
- 2
byte* pSomeArr = new byte[nArrLen];
auto_ptr<byte> bAutoPtr(pSomeArr); // auto delete on exit
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+103
byte* pSomeArr = new byte[nArrLen];
auto_ptr<byte> bAutoPtr(pSomeArr); // auto delete on exit
Защита от утечек памяти! =)
+38.2
platformY = ballY
Непроходимая игра.
1 мячик. 2 Платформы слева и справа.
Это код перемещения платформы робота по y.
+97.4
int main()
{
...
return rand();
}
Иногда даже вылетают ошибки!
+92
if (a > 5)
...
else if (a < 5)
...
else if (i == 5)
...
else
printf ("Сегодня плохой день!");
Плохой день)))
+31.1
void intaIs1intbIs2intcisAplusBHWNDwndIsgetWnd...()
{
int a = 1;
int b = 2;
int c = a + b;
HWND wnd = getWnd();
...
}
Тут все ясно
+150
if (a) b = true; else b = false;
В реале видел. Тупил минут 5, пытаясь понять внутренний смысл этой конструкции
+131.8
class Par_host_port
{
private:
std::string vdata;
public:
//...
char* get () { return (char*)vdata.c_str (); }
};
char const* превращается... Превращается char const*... В char*!
+153
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
+148
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
конвертация строки в число/числа в строку
+139.5
#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;
}
Морской бой