- 1
- 2
- 3
- 4
list<int> list;
...
for(auto i=0;i<list.size();i++){
auto item = *next(list.begin(), i);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+22
list<int> list;
...
for(auto i=0;i<list.size();i++){
auto item = *next(list.begin(), i);
Вчера у меня появился каллега.
http://liveworkspace.org/code/1AWg24$5
Кажется я знаю, кто следующий будет сидеть на табуретке. Думаете стоит сказать ему?
0
Бесконечный оффтоп имени Гологуба #9
#1: https://govnokod.ru/28992 https://govnokod.xyz/_28992
#2: https://govnokod.ru/29053 https://govnokod.xyz/_29053
#3: https://govnokod.ru/29075 https://govnokod.xyz/_29075
#4: https://govnokod.ru/29110 https://govnokod.xyz/_29110
#5: https://govnokod.ru/29127 https://govnokod.xyz/_29127
#6: https://govnokod.ru/29140 https://govnokod.xyz/_29140
#7: https://govnokod.ru/29170 https://govnokod.xyz/_29170
#8: https://govnokod.ru/29192 https://govnokod.xyz/_29192
0
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdbool.h>
struct two_val
{
const int32_t a[2];
};
struct two_val_and_status
{
const bool is_swap;
const struct two_val t_v;
};
struct array
{
const int32_t a[10];
};
struct array_and_status
{
const bool is_swap;
const size_t pos;
const struct array arr;
};
// Эта суперфункцональная функция сортировки двух элементов не просто сортирует два элемента
// но и еще сообщает о том, нужно ли было для этого обменивать два значения
struct two_val_and_status sort2(const struct two_val a)
{
return (a.a[0] > a.a[1]) ? (struct two_val_and_status){true, {{a.a[1], a.a[0]}}} : (struct two_val_and_status){false, a};
}
struct two_val read_two_val(const struct array arr, const size_t pos)
{
return (struct two_val){{arr.a[pos], arr.a[pos+1]}};
}
struct array store_val(const struct array arr, const int32_t val, size_t pos)
{
return (struct array) // Царский анролл
{{
pos != 0 ? arr.a[0] : val,
pos != 1 ? arr.a[1] : val,
pos != 2 ? arr.a[2] : val,
pos != 3 ? arr.a[3] : val,
pos != 4 ? arr.a[4] : val,
pos != 5 ? arr.a[5] : val,
pos != 6 ? arr.a[6] : val,
pos != 7 ? arr.a[7] : val,
pos != 8 ? arr.a[8] : val,
pos != 9 ? arr.a[9] : val
}};
}
struct array store_two_val(const struct array arr, const struct two_val val, const size_t pos)
{
return store_val(store_val(arr,val.a[0],pos),val.a[1],pos+1);
}
// суперохуительная рекурсивная функция сортировки пузырьком
struct array_and_status bubble_sort_rec(struct array_and_status state)
{
if (state.pos == 9)
{
if (state.is_swap == false) // Ура! Сортировка пузырьком завершена!
{
return state;
}
else
{ // а иначе нам надо по-новой сортировать!
return bubble_sort_rec((struct array_and_status){.is_swap = false, .pos=0, .arr = state.arr});
}
}
else
{
const struct two_val_and_status tmp = sort2(read_two_val(state.arr, state.pos));
return bubble_sort_rec(
(struct array_and_status)
{
.is_swap = tmp.is_swap || state.is_swap,
.pos=state.pos+1,
.arr = store_two_val(state.arr, tmp.t_v, state.pos)
}
);
}
}
int main(void)
{
const struct array_and_status a = {.is_swap = false, .pos = 0, .arr = {{8,2,4,1,3,5,7,0,6,9}} };
const struct array_and_status a_sort = bubble_sort_rec(a);
for(size_t i = 0; i < 10; i++) // ох уж это убогое императивное программирование!!!
{
printf("%" PRIu32 ", ", a_sort.arr.a[i]);
}
return EXIT_SUCCESS;
}
Функциональная сортировка пузырьком
https://wandbox.org/permlink/dGyvo82lgQGInD0Y
0
Disk /dev/sdc: 14,46 GiB, 15523119104 bytes, 30318592 sectors
Disk model: Storage Device
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/sdc1 1009664 7802879 6793216 3,2G b W95 FAT32
/dev/sdc2 * 73728 139263 65536 32M 6 FAT16
/dev/sdc3 1 1009664 1009664 493M 85 Linux extended
/dev/sdc5 139264 172031 32768 16M 83 Linux
/dev/sdc6 172032 204799 32768 16M 83 Linux
/dev/sdc7 204800 275455 70656 34,5M 83 Linux
/dev/sdc8 275456 776191 500736 244,5M 83 Linux
/dev/sdc9 776192 976895 200704 98M 83 Linux
/dev/sdc10 976896 1009663 32768 16M 83 Linux
Изначально хотел запихнуть в старый PocketBook515 флешку побольше. Она там хитрая, с линуксом, просто так поменять нельзя. Столкнулся с тем, что не могу parted подвинуть границы раздела, потому что overlapping partitions запрещены. Что делать? вот
fdisk -l0
let a = 1
let b = 2
setTimeout(() => {
[a, b] = [b, a]
console.log(a) // 2
console.log(b) // 1
}, 0)
Дорогие ребята! Сегодня мы с вами будем изучать самые поехавшие способы обмена значениями двух переменных.
https://yandex.ru/turbo?text=https%3A%2F%2Fgames.sololaki. ru%2F4-sposoba-proizvesti-obmen-znacheniyami-peremennyh%2F
+1
#include <array>
#include <iostream>
using namespace std;
int main() {
::array arr {1, 2, 3};
int a, b, c;
::tie(a, b, c) = arr;
printf("%d %d %d",a,b,c);
return 0;
}
https://godbolt.org/z/RRmruC
0
public function comments()
{
$a = new common_articles($this);
switch ($this->prms[3]) {
case 'search':
{
break;
}
default:
{
$where = array();
$itemid = 0;
// и еще полторы сотни строк кода
}
}
}
Параход такой параход...
0
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void *govno[300] = {NULL};
size_t govnopoindex = 0;
void chisti_govno(void)
{
do
{
free(govno[--govnopoindex]);
} while (govnopoindex != 0);
}
char *concat(char *a, char *b)
{
char *ptr = malloc(strlen(a)+strlen(b)+4);
if (ptr == NULL)
{
fprintf(stderr, "Huli ty obosralsya, mudak blyad? Ves' heap zasral\n");
chisti_govno(); // иди под струю мойся
exit(-1);
}
sprintf(ptr, "(%s*%s)", a, b);
govno[govnopoindex++] = ptr;
return ptr;
}
char *pow_gen(size_t n, char *a, char *p)
{
if (n == 0)
{
return a;
}
if (n & 1)
{
return pow_gen(n >> 1, concat(a, p), concat(p, p));
}
else
{
return pow_gen(n >> 1, a, concat(p, p));
}
}
char* pow_b2(size_t n) {
return pow_gen(n, "1", "a");
}
void printfshit(const size_t pow)
{
printf("double pow_%zu(double a) {return %s;}\n\n", pow, pow_b2(pow));
}
int main(void)
{
printfshit(255);
chisti_govno();
return 0;
}
http://govnokod.ru/23246#comment388959 - считаю что это заслуживает отдельного говнокода
+452
const CHANGE_TYPE_ADD = 'add';//add elem in groups
const CHANGE_TYPE_CHANGE = 'change';//add elem
const CHANGE_TYPE_RECHANGE = 'rechange';//edit elem
const CHANGE_TYPE_EDIT = 'edit';//delete element from groups
const CHANGE_TYPE_DEL = 'del';//delete element
Кручу-верчу, запутать хочу
+9
1. http://govnokod.ru/user/register
2. login: zizzleZee
3. email: ****[email protected]
4. >> ВВЕДИТЕ ДЕЙСТВИТЕЛЬНЫЙ АДРЕС!
5. WAT-WAT !!!????
6. http://10minutemail.net -> [email protected]
7. email: [email protected]
8. >> СПАСИБО ЗА РЕГИСТРАЦИЮ!
9. atomic facepalm
govnokod.ru::email_validate
The best practice ever!