- 1
- 2
- 3
- 4
- 5
- 6
- 7
const int MOD = 1000000007;
int pow(int a, int b) {
if (!b) return 1;
if (b & 1) return (pow(a, b - 1) * 1LL * a) % MOD;
return pow((a * 1LL * a) % MOD, b / 2);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
const int MOD = 1000000007;
int pow(int a, int b) {
if (!b) return 1;
if (b & 1) return (pow(a, b - 1) * 1LL * a) % MOD;
return pow((a * 1LL * a) % MOD, b / 2);
}
http://ideone.com/JlfNxZ
Там ещё куча всякого говна есть
http://acm.math.spbu.ru/~kunyavskiy/cpp/
+2
switch (a) {
case 12345:
return 0;
case 14523:
return 1;
case 102543:
return 2;
case 104325:
return 3;
case 243051:
return 4;
case 245130:
return 5;
case 350214:
return 6;
case 351402:
return 7;
case 423150:
return 8;
case 425031:
return 9;
case 530412:
return 10;
case 531204:
return 11;
}
return -1;
−3
if (c & Expression::RefValue) {
scontext += "|RefValue";
}
if (c & Expression::RefParameter) {
scontext += "|RefParameter";
}
if (c & Expression::DeepReference) {
scontext += "|DeepReference";
}
if (c & Expression::ObjectContext) {
scontext += "|ObjectContext";
}
if (c & Expression::InParameterExpression) {
scontext += "|InParameterExpression";
}
if (c & Expression::ExistContext) {
scontext += "|ExistContext";
}
if (c & Expression::UnsetContext) {
scontext += "|UnsetContext";
}
if (c & Expression::AssignmentLHS) {
scontext += "|AssignmentLHS";
}
if (c & Expression::RefAssignmentLHS) {
scontext += "|RefAssignmentLHS";
}
if (c & Expression::DeepAssignmentLHS) {
scontext += "|DeepAssignmentLHS";
}
if (c & Expression::AssignmentRHS) {
scontext += "|AssignmentRHS";
}
if (c & Expression::InvokeArgument) {
scontext += "|InvokeArgument";
}
if (c & Expression::OprLValue) {
scontext += "|OprLValue";
}
if (c & Expression::DeepOprLValue) {
scontext += "|DeepOprLValue";
}
if (c & Expression::AccessContext) {
scontext += "|AccessContext";
}
if (c & Expression::ReturnContext) {
scontext += "|ReturnContext";
}
Нашел тут:
https://github.com/facebook/hhvm/blob/master/hphp/compiler/construct.cpp#L226
0
#if !defined LOG_PRINT_FNAME && !defined LOG_PRINT_LVL && \
!defined LOG_PRINT_DATE && !defined LOG_PRINT_TIME && \
!defined LOG_TIME_FMT && !defined LOG_DATETIME_SEP && \
!defined LOG_PRINT_TIMER && !defined LOG_VERB
#warning No logging options specified, default config will be used
#endif
// Initialize unitialized values
#ifndef LOG_PRINT_FNAME
#define LOG_PRINT_FNAME true
#endif
#ifndef LOG_PRINT_LVL
#define LOG_PRINT_LVL false
#endif
#ifndef LOG_PRINT_DATE
#define LOG_PRINT_DATE false
#endif
#ifndef LOG_PRINT_TIME
#define LOG_PRINT_TIME false
#endif
#ifndef LOG_DATE_FMT
#define LOG_DATE_FMT "%D"
#endif
#ifndef LOG_TIME_FMT
#define LOG_TIME_FMT "%T"
#endif
#ifndef LOG_DATETIME_SEP
#define LOG_DATETIME_SEP ""
#endif
#ifndef LOG_PRINT_TIMER
#define LOG_PRINT_TIMER true
#endif
#ifndef LOG_VERB
#define LOG_VERB 1
#endif
#if LOG_PRINT_TIMER == true && (LOG_PRINT_DATE == true || LOG_PRINT_TIME == true)
#warning Printing timer and datetime both is not possible, datetime will be discarded
#define LOG_PRINT_DATE false
#define LOG_PRINT_TIME false
#endif
enum LogLevel_t {
INFO = 3,
WARNING = 2,
ERROR = 0,
TRACE = 7
};
#define TIMER
#define DATE
#define TIME
#define SEPARATOR
#define FNAME
#define LVL(lvl)
#define STREAM(lvl) \
((lvl) == TRACE || (lvl) == ERROR) ? std::cerr : std::cout
#if LOG_PRINT_TIMER == true
#define TIMER << "[" << std::fixed << Log::getTimer() << "] "
#endif
#if LOG_PRINT_DATE == true
#define DATE << Log::getTimeFmt(LOG_DATE_FMT) << " "
#endif
#if LOG_PRINT_TIME == true
#define TIME << Log::getTimeFmt(LOG_TIME_FMT) << " "
#endif
#if LOG_PRINT_DATE == true && LOG_PRINT_TIME == true
#define SEPARATOR << LOG_DATETIME_SEP
#endif
#if LOG_PRINT_FNAME == true
#define FNAME << __FUNCTION__ << ": "
#endif
#if LOG_PRINT_LVL == true
#define LVL(lvl) << #lvl << ": "
#endif
#define LOG(lvl) \
std::cout.precision(5); \
STREAM(lvl) TIMER DATE SEPARATOR TIME LVL(lvl) FNAME
xxx: Бля, я написал какое-то говно
yyy: Я видел некоторое дерьмо
xxx: Пиздец просто
zzz: Действительно говно.
xxx: Я не знаю даже нахуя я это делал
xxx: Почему-то, когда начинал, мне не пришло в голову, что логгирование на макросах, конфигурируемое в компилтайме — это пиздец
+3
std::string sql = "INSERT INTO digest_test_record (set_id, ref_digest, cand_digest, vdt_cfg_warn, digest_cfg_warn, "
"ref_duration, ref_cardinality, ref_dispersion, "
"cand_duration, cand_cardinality, cand_dispersion, "
"cardinality, difference, red_difference, ext_difference, "
"inv_cardinality, inv_difference, inv_red_difference, inv_ext_difference,
"timing, lib_version) SELECT 0, "
"ROW($1, $2, $3, $4, $5, $6, $7, $8)::digest_info, "
"ROW($9, $10, $11, $12, $13, $14, $15, $16)::digest_info,"
"$17, $18, ",
"$19, $20, $21, "
"$22, $23, $24, "
"$25, $26, $27, $28, "
"$29, $30, $31, $32, "
"$33, ROW($34, $35, $36, make_date($37, $38, $39), $40)::lib_version_info";
cn.prepare("insert", sql);
xact.prepared("insert")
(ref_digest_info.src_width)(ref_digest_info.src_height)(ref_digest_info.src_fps)(ref_digest_info.src_duration)
(ref_digest_info.vdt_duration)(ref_digest_info.cardinality)(ref_digest_info.has_flags)(ref_digest_info.src_filename)
(cand_digest_info.src_width)(cand_digest_info.src_height)(cand_digest_info.src_fps)(cand_digest_info.src_duration)
(cand_digest_info.vdt_duration)(cand_digest_info.cardinality)(cand_digest_info.has_flags)(cand_digest_info.src_filename)
(results.vdt_cfg_warn)(results.digest_cfg_warn)
(results.ref_duration)(results.ref_cardinality)(results.ref_dispersion)
(results.cand_duration)(results.cand_cardinality)(results.cand_dispersion)
(results.cardinality)(results.difference)(results.red_difference)(results.ext_difference)
(results.inv_cardinality)(results.inv_difference)(results.inv_red_difference)(results.inv_ext_difference)
((double)timing / CLOCKS_PER_SEC)(li.main_ver)(li.sub_ver)(li.revision)(li.year)(li.month)(li.day)(li.platform).exec();
Мои глаза.... Яркий пример использования нативного pqxx
+3
int main() {
for (float n = 0, l = 0, q = scanf("%f", &n), r = n, m = (l + r) / 2; r - l > 0.00001 || 0 * printf("%f", l); m*m <= n ? l = m : r = m, m = (l + r) / 2);
}
Просто бинпоиск в одну строчку)
+2
if ( LIKELY( _mode == normal ))
_mode задается один раз в начале программы по конфигурационному файлу.
+3
__fastcall OpenArray(T arg0, T arg1, T arg2, T arg3, T arg4, T arg5, T arg6,
T arg7, T arg8, T arg9, T arg10, T arg11, T arg12,
T arg13, T arg14, T arg15, T arg16, T arg17, T arg18)
{
Array = new T[Count = 19];
Array[0] = arg0;
Array[1] = arg1;
Array[2] = arg2;
Array[3] = arg3;
Array[4] = arg4;
Array[5] = arg5;
Array[6] = arg6;
Array[7] = arg7;
Array[8] = arg8;
Array[9] = arg9;
Array[10] = arg10;
Array[11] = arg11;
Array[12] = arg12;
Array[13] = arg13;
Array[14] = arg14;
Array[15] = arg15;
Array[16] = arg16;
Array[17] = arg17;
Array[18] = arg18;
}
Старый недобрый C++ Builder. Выше по коду еще 17 таких же конструкторов.
0
unsigned int FileScanner::smartBruteForce(QByteArray &haystack, QByteArray &needle)
{
unsigned int count = 0;
unsigned int dataSize = haystack.size();
unsigned int needleSize = needle.size();
unsigned int needleSizeCut = needleSize - 1;
char* dp = haystack.data();
char* np = needle.data();
char lastNeedle = *(np + needleSize - 1);
for(unsigned int i = 0; i < dataSize - needleSize + 1; i++)
{
if(*(dp + (i + needleSizeCut)) != lastNeedle) //This is smart technology ))))
continue;
unsigned int j;
for(j = 0; j < needleSize; j++)
{
if(*(dp + (i + j)) != *(np + j))
break;
}
if(j == needleSize)
count++;
}
return count;
}
−1
bool Diagram::checkIsOverlayElements(const int index)
{
int _x0, _y0, _xX, _yY;
int x0 = _vectorFigure[index]->getCoordinate().getX0();
int y0 = _vectorFigure[index]->getCoordinate().getY0();
int xX = _vectorFigure[index]->getCoordinate().getXx();
int yY = _vectorFigure[index]->getCoordinate().getYy();
for(int _index = 0; _index < _vectorFigure.size(); _index++)
{
_x0 = _vectorFigure[_index]->getCoordinate().getX0();
_y0 = _vectorFigure[_index]->getCoordinate().getY0();
_xX = _vectorFigure[_index]->getCoordinate().getXx();
_yY = _vectorFigure[_index]->getCoordinate().getYy();
if(((x0 >= _x0 && x0 <= xX)
&&(y0 >= _y0 && y0 <= _yY))
||((xX >= _x0 && xX <= _xX)
&&(yY >= _y0 && yY <= _yY))
||((x0 >= _x0 && x0 <= xX)
&&(yY >= _y0 && y0 <= _yY))
||((xX >= _x0 && xX <= _xX)
&&(y0 >= _y0 && yY <= _yY)))
{
return true;
}
}
return false;
}
Проверка наложения фигур друг на друга.