- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
class Par_host_port
{
private:
std::string vdata;
public:
//...
char* get () { return (char*)vdata.c_str (); }
};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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;
}
Морской бой
+133.3
setlocale(0,"");
int x;
cin >> x;
if(x > 10 && x < 0)
{
cout << "Неверный множытель!" << endl;
}
else
{
//...
}
А, я ещё удивлялса, почемуже она работает не так как надо)))
+149
//--------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------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!";}
}
}
Вот нашол у себя на компе такой хеадер))))
Делалса он тупо ради прикола...
+150
_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;
}
Определение дефолтного браузера
+1001.3
void get_tomorrow_date( struct timeval *date )
{
sleep( 86400 ); // 60 * 60 * 24
gettimeofday( date, 0 );
}
На одном индусском форуме программистов задали вопрос: "Как вычислить завтрашнюю дату?".
Ответ был шедевральным и уже разошёлся по всему миру:
+54.9
for( i = 0; i < 2; i++) {
if ((Result = AvCrpSignFile(iSession, szSrcFile, szDstFile, 0)) == AVCRPR_SUCCESS) break;
}
чтобы наверняка
+89
#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);
Говнокод из Вермонда