- 1
- 2
- 3
- 4
if ( tmp - res == 11 )
{
tmp = tmp;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+905.2
if ( tmp - res == 11 )
{
tmp = tmp;
}
Нашел в проэкте сегодня. Кто отгадает, зачем этот код был нужен - тому ничего не будет.
+49.8
bool ok;
double d;
QLocale c(QLocale::C);
d = c.toDouble( "1234.56", &ok ); // ok == true, d == 1234.56
Ссылка на bool!
+60.2
bool CMLayer::operator==(CMLayer ^a, CMLayer ^b)
{
CLayer *pA;
CLayer *pB;
bool bA = false;
bool bB = false;
// Проверка в катче
try
{
pA = a->m_pelMain;
}
catch (System::NullReferenceException ^)
{
pA = NULL;
bA = true;
}
// Проверка в катче
try
{
pB = b->m_pelMain;
}
catch (System::NullReferenceException ^)
{
pB = NULL;
bB = true;
}
if ((bA == true) && (bB == true))
return true;
else if ((bA == true) || (bB == true))
return false;
return pA == pB;
}
Код на Management C++, тот кто его писал был явно в ажуре))))
Проверяются указатели на внутрении данные, а штоб System::NullReferenceException не выскакивал при сравнее на null все сделанно в катче
+144.8
bool PathProcessor::Process(PPProcess *pProcess)
{
std::vector<int> viRoute; int nRouteCount; bool bRetVal = false;
for (int i = 0; i < m_viExcludeStop.size(); i++){
if (m_viExcludeStop[i] == pProcess->nStartStopId) return false;
}
int bbb = 0;
if (pProcess->nRouteId < 0){
viRoute = GetRoutesID(pProcess->nStartStopId);
nRouteCount = viRoute.size();
if (nRouteCount <= 0) return false;
}
else{
viRoute = GetRoutesID(pProcess->nStartStopId, pProcess->nRouteId);
nRouteCount = viRoute.size();
if (nRouteCount <= 0) return false;
nRouteCount = 1;
}
for (int i = 0; i < nRouteCount; i++){
RouteDataInfo rdCur = GetRoute(viRoute[i]);
pProcess->nRoutePartId = rdCur.nId;
PPResult *pRes;
bool bCurRetVal = false;
if (pProcess->bIsFirstStop == true){
pRes = new PPResult();
pRes->bFinished = false;
pRes->nFirstStopId = pProcess->nFirstId;
pRes->nLastStopId = -1;
pRes->nRouteId = rdCur.nRouteId;
m_viResult.push_back(pRes);
}
else pRes = pProcess->pLastResult;
if (pRes != NULL){
PartInfo piTemp(rdCur.nId, rdCur.nLastStopId);
pRes->viPartsId.push_back(piTemp);
}
if (IsEndStop(rdCur.nLastStopId) == true){
if (pRes != NULL){
pRes->bFinished = true;
pRes->nLastStopId = rdCur.nLastStopId;
}
bRetVal = true; bCurRetVal = true;
}
if ((pProcess->IsStopExist(rdCur.nLastStopId) == false) && (bCurRetVal == false)){
if ((pProcess->nCurStep < m_nMaxStep) && (pProcess->nRouteId >= 0)){
PPProcess ppProc;
ppProc.nCurStep = pProcess->nCurStep;
ppProc.nRouteId = pProcess->nRouteId;
ppProc.nStartStopId = rdCur.nLastStopId;
ppProc.pPrevProc = pProcess;
ppProc.bIsFirstStop = false;
ppProc.nFirstId = pProcess->nFirstId;
if (pProcess->pLastResult == NULL) ppProc.pLastResult = pRes;
else ppProc.pLastResult = pProcess->pLastResult;
if (Process(&ppProc) == true) bRetVal = true;
}
else if (pProcess->nCurStep < m_nMaxStep){
PPProcess ppProc;
ppProc.nCurStep = pProcess->nCurStep;
ppProc.nRouteId = rdCur.nRouteId;
ppProc.nStartStopId = rdCur.nLastStopId;
ppProc.pPrevProc = pProcess;
ppProc.bIsFirstStop = false;
ppProc.nFirstId = pProcess->nFirstId;
if (pProcess->pLastResult == NULL) ppProc.pLastResult = pRes;
else ppProc.pLastResult = pProcess->pLastResult;
if (Process(&ppProc) == true) bRetVal = true;
}
if (pProcess->nCurStep+1 < m_nMaxStep){
PPProcess ppProc2;
ppProc2.nCurStep = pProcess->nCurStep+1;
ppProc2.nRouteId = -1;
ppProc2.nStartStopId = rdCur.nLastStopId;
ppProc2.pPrevProc = pProcess;
ppProc2.bIsFirstStop = true;
ppProc2.nFirstId = rdCur.nLastStopId;
ppProc2.pLastResult = NULL;
if (Process(&ppProc2) == true){
PPResult *pRes2;
pRes2 = new PPResult();
pRes2->bFinished = true;
pRes2->nFirstStopId = pRes->nFirstStopId;
pRes2->nLastStopId = rdCur.nLastStopId;
pRes2->nRouteId = pRes->nRouteId;
PPProcess *pProc = pProcess;
while (pProc != NULL){
PartInfo piTemp(pProc->nRoutePartId, pProc->nStartStopId);
pRes2->viPartsId.push_back(piTemp);
pProc = pProc->pPrevProc;
}
m_viResult.push_back(pRes2); bRetVal = true;
}
}
}
}
if ((bRetVal == false) && (pProcess->nRouteId < 0))
m_viExcludeStop.push_back(pProcess->nStartStopId);
return bRetVal;
}
Когда-то давно писал алгоритм поиска маршрутов, теперь удевляюсь как это все работает да еще и не виснет
+144.8
#include "stdafx.h"
#include "windows.h"
#define число int
#define если if
#define иначе else
#define начало {
#define конец }
#define НОЛЬ NULL
#define Сообщение MessageBoxA
#define КНОПКА_ОК MB_OK
#define возврат
#define присвоить =
#define равняется ==
#define больше >
#define ТочкаВхода _tmain
#define Строка _TCHAR
#define УКАЗАТЕЛЬ *
#define КонецСтроки ;
#define СлучайноеЧисло rand
#define Посев srand
#define ВзятьКоличествоТиков GetTickCount
/****************************************************************************************************/
/* */
/****************************************************************************************************/
число ТочкаВхода(число КоличествоПараметров, Строка УКАЗАТЕЛЬ Параметры[])
{
Посев(ВзятьКоличествоТиков());
число новое присвоить СлучайноеЧисло() КонецСтроки
если (новое больше 10000) начало
Сообщение(НОЛЬ, "Больше 10000", НОЛЬ, КНОПКА_ОК) КонецСтроки
конец иначе начало
Сообщение(НОЛЬ, "Меньше 10000", НОЛЬ, КНОПКА_ОК) КонецСтроки
конец
возврат 0 КонецСтроки
}
Ооо могучий C++
+144.8
A* arr = new A[size];
std::vector<A*> vec(size);
for(size_t i=0; i<size; ++i)
vec.push_back(&a[i])
// Do something with vec
delete[] arr;
+144.8
/**
* Helper classes for computing window query on rectangles
*/
class VerticalSegmentIntersect : public std::unary_function < PRGlyph, ptrdiff_t > {
ptrdiff_t m_Lhs;
ptrdiff_t m_Rhs;
public:
VerticalSegmentIntersect ( ptrdiff_t top, ptrdiff_t bottom ) throw() : m_Lhs(top+top), m_Rhs(bottom+bottom) {}
ptrdiff_t operator() ( PRGlyph inpGlyph ) const throw() {
QRect const* area = inpGlyph->GetGlyphArea();
ptrdiff_t x = area->bottom() + area->top(), y = area->bottom() - area->top();
if (y < x - m_Rhs ) return 0;
if (y < m_Lhs - x ) return 0;
return 1;
}
};
class HorisontalSegmentIntersect : public std::unary_function < PRGlyph, ptrdiff_t > {
ptrdiff_t m_Lhs;
ptrdiff_t m_Rhs;
public:
HorisontalSegmentIntersect ( ptrdiff_t left, ptrdiff_t right ) throw() : m_Lhs(left+left), m_Rhs(right+right) {}
ptrdiff_t operator() ( PRGlyph inpGlyph ) const throw() {
QRect const* area = inpGlyph->GetGlyphArea();
ptrdiff_t x = area->right() + area->left(), y = area->right() - area->left();
if (y < x - m_Rhs ) return 0;
if (y < m_Lhs - x ) return 0;
return 1;
}
};
/**
* Helper classes for computing containment query on rectangles
*/
class VerticalSegmentContains : public std::unary_function < PRGlyph, ptrdiff_t > {
ptrdiff_t m_Lhs;
ptrdiff_t m_Rhs;
public:
VerticalSegmentContains ( ptrdiff_t top, ptrdiff_t bottom ) throw() : m_Lhs(top+top), m_Rhs(bottom+bottom) {}
ptrdiff_t operator() ( PRGlyph inpGlyph ) const throw() {
QRect const* area = inpGlyph->GetGlyphArea();
ptrdiff_t x = area->bottom() + area->top(), y = area->bottom() - area->top();
if ( y > x - m_Lhs ) return 0;
if ( y > m_Rhs - x ) return 0;
return 1;
}
};
class HorisontalSegmentContains : public std::unary_function < PRGlyph, ptrdiff_t > {
ptrdiff_t m_Lhs;
ptrdiff_t m_Rhs;
public:
HorisontalSegmentContains ( ptrdiff_t left, ptrdiff_t right ) throw() : m_Lhs(left+left), m_Rhs(right+right) {}
ptrdiff_t operator() ( PRGlyph inpGlyph ) const throw() {
QRect const* area = inpGlyph->GetGlyphArea();
ptrdiff_t x = area->right() + area->left(), y = area->right() - area->left();
if ( y > x - m_Lhs ) return 0;
if ( y > m_Rhs - x ) return 0;
return 1;
}
};
// compute the window query on m_GlyphData rectangles
QVector<PRGlyph> :: iterator windowq = m_Selection.isValid() ?
std::partition ( m_GlyphData.begin(),
std::partition ( m_GlyphData.begin(), m_GlyphData.end(), VerticalSegmentIntersect ( m_Selection.top(), m_Selection.bottom() ) ),
HorisontalSegmentIntersect ( m_Selection.left(), m_Selection.right() )
) : m_GlyphData.begin();
// compute the containment query on window query rectangles (the containment query resuls is always subset of window query )
QVector<PRGlyph> :: iterator containq = std::partition ( m_GlyphData.begin(),
std::partition ( m_GlyphData.begin(), windowq, VerticalSegmentContains ( m_Selection.top(), m_Selection.bottom() ) ),
HorisontalSegmentContains ( m_Selection.left(), m_Selection.right() )
);
Способ быстренько находить прямоугольники, пересекающиеся с входным и содержимые им же. Применимо для прямоугольных параллелепипедов любой размерности.
+912.2
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if(n==1) cout<<"A";
if(n==2) cout<<"B";
if(n==3) cout<<"AB";
if(n==4) cout<<"BAB";
if(n==5) cout<<"ABBAB";
if(n==6) cout<<"BABABBAB";
if(n==7) cout<<"ABBABBABABBAB";
if(n==8) cout<<"BABABBABABBABBABABBAB";
if(n==9) cout<<"ABBABBABABBABBABABBABABBABBABABBAB";
if(n==10) cout<<"BABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBAB";
if(n==11) cout<<"ABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBAB";
if(n==12) cout<<"BABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBAB";
if(n==13) cout<<"ABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBAB";
if(n==14) cout<<"BABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBAB";
if(n==15) cout<<"ABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBAB";
return 0;
}
строки Фибаначи. (=
+54.6
#include <iostream>
class TerVer {
public:
short d1, d2, d3, d4;
short totalCounter, goodCounter;
bool DoneInc;
TerVer(): d1(1), d2(0), d3(0), d4(0), totalCounter(1), goodCounter(0), DoneInc(false) {}
bool IsGood() {
return (
(d1==d2 && d1!=d3 && d1!=d4 && d3!=d4) ||
(d1==d3 && d1!=d2 && d1!=d4 && d2!=d4) ||
(d1==d4 && d1!=d2 && d1!=d3 && d2!=d3) ||
(d2==d3 && d2!=d1 && d2!=d4 && d1!=d4) ||
(d2==d4 && d2!=d1 && d2!=d3 && d1!=d3) ||
(d3==d4 && d3!=d1 && d3!=d2 && d1!=d2)
) ? true : false;
}
void Inc() {
d4++;
if(d4>9) { d4=0; d3++; if(d3>9) {d3=0; d2++; if(d2>9) { d2=0; d1++; if(d1>9) DoneInc = true; } } }
if (!DoneInc) { totalCounter++; if (IsGood()) goodCounter++; }
}
};
int main() {
TerVer z;
while(!z.DoneInc) {
z.Inc();
}
cout << z.goodCounter << " / " << z.totalCounter << " = " << (double)z.goodCounter/z.totalCounter << endl;
return 0;
}
Найти вероятность того, что в случайном четырехзначном числе ровно две цифры совпадают.
Вот что бывает, когда лень думать.
+940.8
bool checkForExe(std::string ext)
{
return ext==".exe" ? true :
ext==".Exe" ? true :
ext==".eXe" ? true :
ext==".EXe" ? true :
ext==".exE" ? true :
ext==".ExE" ? true :
ext==".eXE" ? true :
ext==".EXE" ? true : false;
}
Нашел в одной моей очень древней программе-шутке. Регистронезависимая проверка на расширение .exe.