- 1
- 2
- 3
[]() { std::function<int(int)> foo =
[&foo](int k) { return k == 1 ? 1 : k + foo(k-1); };
return foo; }()(3)
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+50
[]() { std::function<int(int)> foo =
[&foo](int k) { return k == 1 ? 1 : k + foo(k-1); };
return foo; }()(3)
Как написать рекурсивную лямбдру на крестах?
+132
rc = system
(
"test "
"`ls -1 $WORKDIR/somedir/ | wc -l` = 1"
" -a "
"`ls -1 $WORKDIR/somedir/*/somefiles.* | wc -l` = 1"
);
ASSERTM( rc != -1, "check for number of <dirs>" );
ASSERTM( rc == 0, "number of <some> files is greater than 1" );
по мотивам http://govnokod.ru/14374
из теста. да, можно было на С написать. да, мне было просто лень.
−95
[dic setObject:[NSNumber numberWithInt:TWITTER] forKey:@"source"];
Как можно простые вещи сделать сложными.
Эквивалентно: dict[@"source"] = @(TWITTER);
+132
procedure tmythread.execute;
var i:integer;
begin
bot.postnumber:=topicno; bot.proxy:='220.181.89.72:8000'; bot.login:=copy(vote,1,pos(':',vote)-1); bot.password:=copy(vote,pos(':',vote)+1,length(vote));
case actiontype of
ac_dec:
begin
bot.comment:=false;
try
bot.connect;
except
terminate;
end;
bot.VoteAgainst;
end;
ac_inc:
begin
bot.comment:=false;
try
bot.connect;
except
terminate;
end;
bot.VoteOn;
end;
ac_deccurrent:
begin
bot.comment:=true;
try
bot.connect;
except
terminate;
end;
bot.VoteAgainst;
end;
ac_inccurrent:
begin
bot.comment:=true;
try
bot.connect;
except
terminate;
end;
bot.VoteOn;
end;
ac_decall:
begin
bot.comment:=true;
try
bot.connect;
except
terminate;
end;
for i:=0 to clist.Count-1 do
begin
bot.postnumber:=clist[i];
bot.VoteAgainst;
end;
end;
ac_incall:
begin
bot.comment:=true;
try
bot.connect;
except
terminate;
end;
for i:=0 to clist.Count-1 do
begin
bot.postnumber:=clist[i];
bot.VoteOn;
end;
end;
ac_decallc:
begin
bot.comment:=true;
try
bot.connect;
except
terminate;
end;
for i:=0 to clist.Count-1 do
begin
bot.postnumber:=clist[i];
bot.VoteAgainst;
end;
end;
ac_incallc:
begin
bot.comment:=true;
try
bot.connect;
except
terminate;
end;
for i:=0 to clist.Count-1 do
begin
bot.postnumber:=clist[i];
bot.VoteOn;
end; end; end; end;
Код Того-На-Кого-Не-Будем-Показывать-Пальцем
ВНИМАНИЕ! Некоторые строки были объединены дабы вместиться в пост
+20
Matrix matrix ( h, w );
delete &h, &w;
for ( int i = 0; i < h; i++ )
{
for ( int j = 0; j < w; j++ )
{
cout << "Введите элемент [" << i << ", " << j << "]: ";
cin >> matrix[i][j];
}
}
Найди ошибку...
−88
while ii<kol:
a = random.random()
z = str(a)
L = len(z)
i = 0
while i <L:
if z[i]=="0":
s0 +=1
elif z[i]=="1":
s1 +=1
elif z[i]=="2":
s2 +=1
elif z[i]=="3":
s3 +=1
elif z[i]=="4":
s4 +=1
elif z[i]=="5":
s5 +=1
elif z[i]=="6":
s6 +=1
elif z[i]=="7":
s7 +=1
elif z[i]=="8":
s8 +=1
elif z[i]=="9":
s9 +=1
i+=1
ii +=1
массивы для питухов
http://habrahabr.ru/post/183022/
+157
#include <iostream>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/key_type.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/string.hpp>
#include <boost/mpl/for_each.hpp>
using namespace boost;
typedef mpl::map<
mpl::pair<mpl::string<'H','e','l','l','o'>, mpl::int_<0>>,
mpl::pair<mpl::string<',',' '>, mpl::int_<1>>,
mpl::pair<mpl::string<'W','o','r','l','d','!'>, mpl::int_<2>>
> map;
struct do_some {
template<typename T>
void operator()(T) const {
std::cout << mpl::c_str<T>::value;
}
};
int main() {
mpl::for_each<
map,
typename mpl::lambda<
mpl::key_type<map, mpl::_1>
>
>(do_some());
}
еще один хеловорд.
+152
class ListEl{
public:
int val;
ListEl *head;
ListEl *tail;
}
class MyList{
public:
ListEl *head, *tail;
0
#include <stdio.h>
struct{int a; float b;} test()
{
return (typeof(test())){1337, 666.666};
}
int main()
{
auto a = test();
printf("%d %f\n", a.a, a.b);
return 0;
}
В стандарт C23 добавили auto и теперь можно писать такую хуйню. В "Clang" работает: https://godbolt.org/z/GG3addqPb
+1
#include <iostream>
using namespace std;
void Brezenhem(char **z, int x0, int y0, int x1, int y1)
{
int A, B, sign;
A = y1 - y0;
B = x0 - x1;
if (abs(A) > abs(B)) sign = 1;
else sign = -1;
int signa, signb;
if (A < 0) signa = -1;
else signa = 1;
if (B < 0) signb = -1;
else signb = 1;
int f = 0;
z[y0][x0] = '*';
int x = x0, y = y0;
if (sign == -1)
{
do {
f += A*signa;
if (f > 0)
{
f -= B*signb;
y += signa;
}
x -= signb;
z[y][x] = '*';
} while (x != x1 || y != y1);
}
else
{
do {
f += B*signb;
if (f > 0) {
f -= A*signa;
x -= signb;
}
y += signa;
z[y][x] = '*';
} while (x != x1 || y != y1);
}
}
int main()
{
const int SIZE = 25; // размер поля
int x1, x2, y1, y2;
char **z;
z = new char*[SIZE];
for (int i = 0; i < SIZE; i++)
{
z[i] = new char[SIZE];
for (int j = 0; j < SIZE; j++)
z[i][j] = '-';
}
cout << "x1 = "; cin >> x1;
cout << "y1 = "; cin >> y1;
cout << "x2 = "; cin >> x2;
cout << "y2 = "; cin >> y2;
Brezenhem(z, x1, y1, x2, y2);
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < SIZE; j++)
cout << z[i][j];
cout << endl;
}
cin.get(); cin.get();
return 0;
}
https://prog-cpp.ru/brezenham/
спойлер: автор тян