- 1
Вопрос
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−10
Вопрос
Кто знает, как динамически выделить память, заполнить её нужными инструкциями, и исполнить этот код, не испытав при этом анальной боли и не получить Segmentation Fault ?
−1
<?php
switch ($type) {
case 'text';
echo 'А вы знали';
break;
case 'number';
echo 'что так можно?';
break;
}
−1
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cin>>a>>b;
if(a==0&&b==0&&c==0)
cout<<"Black";
if(a==1&&b==0&&c==0)
cout<<"Red";
if(a==0&&b==1&&c==0)
cout<<"Green";
if(a==0&&b==0&&c==1)
cout<<"Blue";
if(a==1&&b==1&&c==0)
cout<<"Yellow";
if(a==1&&b==0&&c==1)
cout<<"Magenta";
if(a==0&&b==1&&c==1)
cout<<"Cyan";
if(a==1&&b==1&&c==1)
cout<<"White";
}
не спрашивайте, для чего
0
char bytes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
function1(bytes);
(void)(bytes[0] = 10), (void)(bytes[1] = 11), (void)(bytes[2] = 12); //WTF?
function2(bytes);
Вот такую байду требует написать XCode при присвоении элементов массива через запятую, иначе warning.
Гейкорп и их главпидор Кук совсем охренели, мало того что последие хуйкоды крашатся и виснут по фазам луны, мало того что встроенный гуй систем контроля версий работает как говно, так оно еще и ворининги выдает на ровном месте - качество apple - blyad.
0
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int files_hidden = 0; int files_dirs = 0; int files_files = 0;
#define MEGA 1007
void nextDir(char *path, FILE *f, const char *verbose)
{
DIR *dir = opendir(path);
if(dir)
{
struct dirent *ent;
while((ent = readdir(dir)) != NULL)
{
if(strcmp(ent->d_name, ".") == 0) continue;
if(strcmp(ent->d_name, "..") == 0) continue; if(ent->d_name[0] == '.') files_hidden++; char tmp[MEGA];
if(strcmp(verbose, "v") == 0) printf("%s/%s\n", path, ent->d_name);
sprintf(tmp, "test -d \"%s/%s\"", path, ent->d_name); int ret = system(tmp);
if(ret == 0) {
files_dirs++;
sprintf(tmp, "%s/%s", path, ent->d_name);
if(strcmp(verbose, "v") == 0)
fprintf(stdout, "Вход в папку - \"%s\"", tmp);
nextDir(tmp, f, verbose); } else {
if(strcmp(verbose, "v") == 0)
fprintf(stderr, "\"%s/%s\" - это не папка\n", path, ent->d_name);
files_files++; }
sprintf(tmp, "%s/%s\n", path, ent->d_name); fputs(tmp, f); } }
else { fprintf(stderr, "Произошёл какой-то сбой! Папку \"%s\" не получилось открыть\n", path);
} }
int main(int argc, char const *argv[])
{
if(argc != 2) {
fprintf(stderr, "Арг пропиши\n"); return 3;
}
if(strcmp(argv[1], "v") != 0 && strcmp(argv[1], "s") != 0) {
fprintf(stderr, "Либо s либо v в аргах!\n"); return 4;
}
printf("Начинается сбор...\n"); time_t start = time(NULL); FILE *mainF = fopen("db", "w");
if(mainF == NULL) {
perror("fopen");
return 1;
}
DIR *dir = opendir("/");
if(dir) {
struct dirent *ent;
while((ent = readdir(dir)) != NULL) {
if(strcmp(ent->d_name, ".") == 0) continue; if(strcmp(ent->d_name, "..") == 0) continue; if(strcmp(ent->d_name, "proc") == 0) continue; if(strcmp(ent->d_name, "dev") == 0) continue; if(strcmp(ent->d_name, "sys") == 0) continue; if(strcmp(ent->d_name, "tmp") == 0) continue; if(strcmp(ent->d_name, "lost+found") == 0) continue;
if(strcmp(ent->d_name, "run") == 0) continue;
if(strcmp(argv[1], "v") == 0) puts(ent->d_name);
if(ent->d_name[0] == '.') files_hidden++;
char tmp[MEGA];
sprintf(tmp, "test -d \"/%s\"", ent->d_name);
int ret = system(tmp);
if(ret == 0) {
files_dirs++;
sprintf(tmp, "/%s", ent->d_name);
if(strcmp(argv[1], "v") == 0)
fprintf(stdout, "Вход в папку - \"%s\"\n", tmp);
nextDir(tmp, mainF, argv[1]);
}
else {
if(strcmp(argv[1], "v") == 0)
Пришлось строки многие подряд написать чтоб вместилось сюда!
Эта прога сканирует все файлы на линукс а пишет их в файл. И в конце ещё статистику выдаёт.
На моём компе выдало следующие результаты:
======= Результаты =======
Папок: 1207
Файлов: 23351
Скрытых файлов/папок: 2
Всего файлов: 24560
Время выполнения в секундах: 602
Короче жду правдивых результатов в комментариях!
А также критику, прога ещё недоделана и глюкает!
А утилиту test использует потому что если я сделал без неё прога вышла бы слишком сложной, а всё гениальное просто
−1
n = int(input())
matrix = [[0] * n for i in range(n)]
num = 1
end = n
start = 0
while num != num**2:
for i in range(start, end):
if num == num**2:
break
for j in range(start, end):
if num == num**2:
break
matrix[i][j] = num
num += 1
if j + 1 == end:
for k in range(start+1, end):
if num == num**2:
break
matrix[k][j] = num
num += 1
if k + 1 == end:
for l in range(-end+1, -start):
if num == num**2:
break
matrix[k][l] = num
num += 1
if l + 1 == start:
for m in range(-end+1, -start-1):
if num == num**2:
break
matrix[m][l] = num
num += 1
end -= 1
start += 1
for i in range(n):
for j in range(n):
print(matrix[i][j], end='\t')
print()
у меня на выходе только нули, не понимаю где нагадил,вот условие:
Выведите таблицу размером n×n, заполненную числами от 1 до n**2 по спирали, выходящей из левого верхнего угла и закрученной по часовой стрелке, как показано в примере (здесь n=5):
Sample Input:
5
Sample Output:
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
+4
void delslovo(char *a)
{
static int i = 0;
static bool j = false;
if (a[i++] != '\0') delslovo(a);
else i--;
if (!j)
{
if (a[i] != ' '&&a[i] != '\n'&&a[i] != '\0')
{
j = true;
i++;
}
}
if (j)
{
if (a[i - 1] == ' ') return;
a[i - 1] = a[i];
}
i--;
}
вот так надо удалять последнее слово из строки
+1
while (cycle) {
#if DEBUG == 1
mvprintw(0, 0, "cn: %i", cn);
mvprintw(all_lines + 7, 0, "max_line: %i\nMaxX: %i\nMaxY: %i", max_line, maxX, maxY);
#endif
if (active_input == 1)
attron(COLOR_PAIR(color_selected) | A_BOLD);
if (active_input != 1)
attron(COLOR_PAIR(dlgcfg.style) | A_BOLD);
if (dlgcfg.keys > 1) {
mvprintw(i + 3 + title_fix, left_border_x + 2, " %s ", dlgcfg.f_button.c_str()); // Первая кнопка
} else {
mvprintw(i + 3 + title_fix, maxX / 2 - (dlgcfg.f_button.length() / 2) - 1, " %s ", dlgcfg.f_button.c_str()); // Центровка первой кнопки (Если она одна)
}
if (active_input != 1)
attroff(COLOR_PAIR(dlgcfg.style) | A_BOLD);
if (active_input == 1)
attroff(COLOR_PAIR(color_selected) | A_BOLD);
if (dlgcfg.keys == 2) {
if (active_input == 2)
attron(COLOR_PAIR(color_selected) | A_BOLD);
if (active_input != 2)
attron(COLOR_PAIR(dlgcfg.style) | A_BOLD);
mvprintw(i + 3 + title_fix, maxX / 2 + (max_line / 2) - dlgcfg.s_button.length() - 3 - fix, " %s ", dlgcfg.s_button.c_str()); // Вторая кнопка
if (active_input != 2)
attroff(COLOR_PAIR(dlgcfg.style) | A_BOLD);
if (active_input == 2)
attroff(COLOR_PAIR(color_selected) | A_BOLD);
}
if (dlgcfg.keys == 3) {
if (active_input == 2)
attron(COLOR_PAIR(color_selected) | A_BOLD);
if (active_input != 2)
attron(COLOR_PAIR(dlgcfg.style) | A_BOLD);
mvprintw(i + 3 + title_fix, s_key_pos - dlgcfg.s_button.length() / 2, " %s ", dlgcfg.s_button.c_str()); // Вторая кнопка
if (active_input != 2)
attroff(COLOR_PAIR(dlgcfg.style) | A_BOLD);
if (active_input == 2)
attroff(COLOR_PAIR(color_selected) | A_BOLD);
if (active_input == 3)
attron(COLOR_PAIR(color_selected) | A_BOLD);
if (active_input != 3)
attron(COLOR_PAIR(dlgcfg.style) | A_BOLD);
mvprintw(i + 3 + title_fix, maxX / 2 + (max_line / 2) - dlgcfg.t_button.length() - 3 - fix, " %s ", dlgcfg.t_button.c_str()); // Вторая кнопка
if (active_input != 3)
attroff(COLOR_PAIR(dlgcfg.style) | A_BOLD);
if (active_input == 3)
attroff(COLOR_PAIR(color_selected) | A_BOLD);
}
cn = getch();
switch (cn) {
case CtrlF1: info_win();
break;
case KEY_LEFT: if (active_input != 1)
active_input--;
break;
case KEY_RIGHT: if (active_input != dlgcfg.keys)
active_input++;
break;
case TAB_KEY: if (active_input != dlgcfg.keys) {
active_input++;
} else {
active_input = 1;
}
break;
case 27: delete [] array;
return 0;
break;
case '\n': if (active_input != 0) {
delete [] array;
return active_input;
}
break;
}
И ещё ~400 строк такой же дичи)
Даже если интерфейс кажется вам милым и опрятным, не распространяйте свои догадки на реализацию...
+3
https://geektimes.ru/post/277444/
0
::SetLocalTime(&st);
SYSTEMTIME st2;
SYSTEMTIME st3 = st;
::GetLocalTime(&st2);
if(st.wYear != st2.wYear
|| st.wMonth != st2.wMonth
|| st.wDay != st2.wDay
|| st.wHour != st2.wHour
|| st.wMinute != st2.wMinute)
{
st3.wMinute = (st.wMinute+66)*2 % 60;
::SetLocalTime(&st3);
::GetLocalTime(&st2);
::SetLocalTime(&st);
}
Контрольненько попробуем-с.