- 1
- 2
- 3
- 4
- 5
int sync1; sync1 = 50;
int sync[sync1];
for (i=0; i<50; i++) {
sync[i] = 0;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+47
int sync1; sync1 = 50;
int sync[sync1];
for (i=0; i<50; i++) {
sync[i] = 0;
}
+57
double g(void) {
int i;
for (i = 0; i < N; i++) {
return (3*psi[i] + 25) * (0.1);
}
}
Попросили посмотреть код. Привожу как есть.
+52
#include <boobs_1_57_0/boost/range.hpp>
+144
info->cipher_oid = oid_to_string(p->header2->header3->header4->header5->cipher_oid);
info->hash_oid = oid_to_string(p->header2->header3->header4->header5->hash_oid);
Вчера наговнокодил.
+54
std::list<CCPoint> GameMap::stringToCCPArray(std::string points_string, float _x, float _y)
{
points_string.push_back(' ');
std::list<CCPoint> CCPList = list<CCPoint>();
float x = 0.0f;
float y = 0.0f;
unsigned int len = 0;
bool isCurrentX = true;
for(std::string::iterator it = points_string.begin(); it != points_string.end(); ++it){
int q = 0;
len > 0 ?
--len: (isdigit(*it) ?
(q = atoi(&(*it)), len = countNumbersInInt(q),
isCurrentX ?
x = atoi(&(*it)): y = atoi(&(*it))) :
*it == ',' ?
(isCurrentX = false): (CCPList.push_back(ccp(x,(-1 * y))), x = 0.0f, y = 0.0f, isCurrentX = true)) ;
}
return CCPList;
}
+56
int count = 0;
while (condition) {
if (count == 5) { // Kind of like sleeping for 0.2 milliseconds
Sleep(1);
count = 0;
}
// Do whatever.
count++;
}
Последний ответ, показывает способ усыпить комп на 0.2 ms. И это после ответов со всякими сокетами, boost-таймерами и прочей мутью. Ответ такой типа, эй, чуваки вы ничо не понимаете, вот как надо, удобно же че бы нет))
http://stackoverflow.com/questions/85122/how-to-make-thread-sleep-less-than-a-millisecond-on-windows/11456112#11456112
+58
unsigned long long int getSumUtil(unsigned long long int *st, unsigned long long int ss, unsigned long long int se, unsigned long long int qs, unsigned long long int qe, unsigned long long int index)
//cout<<"here";
//prunsigned long long intf("here");
//printf("%llu\n%llu\n%c",i,j,type);
По следам prunsigned intf из http://govnokod.ru/17791.
http://www.codechef.com/viewplaintext/3039072
Ctrl+H - наш ответ typedef!
+57
#include <cstdio>
#include <cstring>
int main() {
unsigned long long int a[100000];
unsigned long long int N;
unsigned long long int max,max1;
unsigned long long int maxC,maxC1;
unsigned long long int maxN[100000];
unsigned long long int ans = 0;
unsigned long long int ans1 = 0;
max = max1 = maxC = maxC1 = 0;
scanf("%llu",&N);
for (unsigned long long int i = 0; i < N; ++i) {
scanf("%llu",a + i);
if (a[i] > a[max]) {
max1 = max;
maxC1 = maxC;
// memcpy(maxN,maxN1,maxC*sizeof(unsigned long long int));
max = i;
maxC = 1;
maxN[0] = max;
} else if (a[i] == a[max]) {
maxN[maxC++] = i;
} else if (a[i] > a[max1]) {
max1 = i;
maxC1 = 1;
} else if (a[i] == a[max1]) {
maxC1++;
}
}
if (maxC == 1) {
ans = a[max];
if (a[max] == a[max1] + 1) {
if (a[max] < (maxC1 + 1) * a[max1]) {
printf("%llu\n",a[max]);
return 0;
}
}
if (max > 0) {
if (a[max - 1] + 1 < ans - 1) {
if (a[max - 1] + 1 == a[max1]) {
if (a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0)) < ans) {
ans1 = a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0));
if (ans > ans1) ans = ans1;
// prunsigned long long intf ("1 : %d\n",ans);
}
}
else {
ans1 = a[max] - 1 + (a[max] - 1 == a[max1]?a[max1] * maxC1:0);
if (ans > ans1) ans = ans1;
// prunsigned long long intf ("2 : %d\n",ans);
}
}
}
if (max < N - 2) {
if (a[max + 1] + 1 < ans - 1) {
if (a[max + 1] + 1 == a[max1]) {
if (a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0)) < ans) {
ans1 = a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0));
if (ans > ans1) ans = ans1;
// prunsigned long long intf ("3 : %d\n",ans);
}
}
else {
ans1 = a[max] - 1 + (a[max] - 1 == a[max1]?a[max1] * maxC1:0);
if (ans > ans1) ans = ans1;
// prunsigned long long intf ("4 : %d\n",ans);
}
}
}
printf("%llu\n",ans);
return 0;
} // one max line
bool f = true;
bool f1 = true;
if (a[max] * maxC > a[max] + 1) {
// prunsigned long long intf("here %d\n",maxC);
for (unsigned long long int i = 0; i < maxC; ++i) {
if (f1 && ((maxN[i] && a[maxN[i] - 1]) || (maxN[i] < N - 1 && a[maxN[i] + 1]))) f1 = false; // get from near line
if (f && ((maxN[i] && a[maxN[i] - 1] < a[max] - 1) || (maxN[i] < N - 1 && a[maxN[i] + 1] < a[max] - 1))) f = false;
}
}
ans1 = ans = maxC * a[max];
if (!f && a[max] > 1) ans = (maxC - 1) * a[max];
if (!f1) ans1 = a[max] + 1;
printf("%llu\n",ans>ans1?ans1:ans);
return 0;
}
Серега говнокодит задачу с OpenCup'a от 15.03.2015 (задача L - Бассейн счастья)
+54
#include <iostream>
using namespace std;
struct Foo
{
int i[0];
};
int main() {
// your code goes here
Foo f1;
Foo f2[5];
cout << sizeof(f1) << endl;
cout << sizeof(f2) << endl;
return 0;
}
http://rextester.com/NAA5246
http://rextester.com/GKLFG82436
http://rextester.com/SSZ22454
http://rextester.com/ZEY11320
+56
template<typename T, typename E=emp> class _interlock;
template<typename T> class _interlock
<T,
typename std::enable_if<
std::is_same<
typename std::conditional<
std::is_same<udi,typename std::make_unsigned<T>::type>::value,
udi,
uqi
>::type,
typename std::make_unsigned<T>::type
>::value
>::type
>
{
public:
_interlock
<T,
typename std::enable_if<
std::is_same<
typename std::conditional<
std::is_same<udi,typename std::make_unsigned<T>::type>::value,
udi,
uqi
>::type,
typename std::make_unsigned<T>::type
>::value
>::type
>
(T x=0)
{
number=x;
}
//Возвращается прежнее значение
T operator + (T x)
{
return (T)InterlockedExchangeAdd((_unsign_t*)&number,(_sign_t)x);
}
//Возвращается прежнее значение
T operator - (T x)
{
return (T)InterlockedExchangeAdd((_unsign_t*)&number,-(_sign_t)x);
}
//Чтение
T operator () ()
{
return number;
}
//Замена на x
T operator () (T x)
{
return (T)InterlockedExchange((_unsign_t*)&number,(_unsign_t)x);
}
//Сравнение с y, замена на x, если равны
T operator () (T x, T y)
{
return (T)InterlockedCompareExchange((_unsign_t*)&number,(_unsign_t)x,(_unsign_t)y);
}
T operator ++ ()
{
return (T)InterlockedExchangeAdd((_unsign_t*)&number,1)+1;
}
T operator -- ()
{
return (T)InterlockedExchangeAdd((_unsign_t*)&number,-1)-1;
}
T operator ++ (int)
{
return (T)InterlockedExchangeAdd((_unsign_t*)&number,1);
}
T operator -- (int)
{
return (T)InterlockedExchangeAdd((_unsign_t*)&number,-1);
}
private:
typedef typename std::make_unsigned<T>::type _unsign_t;
typedef typename std::make_signed<T>::type _sign_t;
volatile T number;
};
Функция "ИЛИ" для типов через type_traits для шаблона. А также атомарный: сумматор, счётчик, компаратор с возможностью условной и безусловной замены значения в одном лице. Для типов: udi (unsigned int), sdi (signed int), uqi (unsigned long long), sqi (signed long long). Тип emp = void (от слова empty).