- 1
 
Передайте  Камрану Амини что он Большое Хуйло
                                    Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 7
−4
Передайте  Камрану Амини что он Большое Хуйло
                                    
+1
int my_strcmp(const char *out, const char *in   ){
  for( ;*(in) , *(out) &&  *(in) == *(out); *out++,*in++  );
	   return   *in <= *out ?  *out > *in   : -1   ;
	}
                                    Бульк
0
void  converting(char *in, char *out, node *PTR, char (checking_stack)(node), void (push)(node *topPTR, char value), int (pop)(node *fix), int (isOper)(char c), int (precedence_intro)(char data_1, char  data_2, int(intro_precedence_power)(int res_1, int  res_2)), int(intro_precedence_power)(int res_1, int  res_2)) {
	int k = 0, j = 0, d = 0;
	
	push(PTR, '(');
	
	for (k = 0; checking_stack((node)PTR) != 0; k++) {
	
		if (isdigit(in[k])) {
			
			out[j++] = in[k];
		}
		if (in[k] == '(') {
			push(PTR, in[k]);
		}
		if (isOper(in[k]) == 1) {
			while (precedence_intro((*PTR)->alpha, in[k], intro_precedence_power) != -1) {
				out[j++] = pop(PTR);
			}
			push(PTR, in[k]);
		}
		
		if (in[k] == ')') {
			d = pop(PTR);
			for (; d != '('; d = pop(PTR)) {
				out[j++] = d;
			}
		}
	}
}
int precedence(char data_1, char   data_2, int(intro_precedence_power)(int res_1, int  res_2))  {
 char collection[] = "+1-1*2/2^3";	
 
 char	buf_1 = (char)strcspn(  collection , &data_1) + 1;
 char	buf_2 = (char)strcspn(collection, &data_2) + 1;
	return   intro_precedence_power(atoi(&collection[buf_1]), atoi(&collection[buf_2]));
}
int precedence_power(int res_1, int  res_2) {
	if (res_1 < res_2) {
		return   -1;
	}
	else	if (res_1 == res_2) {
		return 	  0;
	}
	else	if (res_1 > res_2) {
		return	  1;
	}
	return 0;
}
                                    Якобы вычисляет обратною польскою нотацию номер два
0
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define  MAX 300
struct stack {
	char alpha;
	struct stack *nxtPTR;
};
typedef struct stack  Stack;
typedef  Stack *node;
void  message(void);
char out_print(char word[]);
int precedence_power(int res_1, int  res_2);
int pop(node *topPtr);
void push_stack(node *topPTR, char value);
int pop(node  *topPTR);
char check_stack(node data);
int isOperator(char c);
int precedence(char data_1, char   data_2, int(intro_precedence_power)(int res_1, int  res_2));
void  converting(char *in, char *out, node *PTR, char (checking_stack)(node), void (push)(node *topPTR, char value), int (pop)(node *fix), int (isOper)(char c), int (precedence_intro)(char data_1, char  data_2, int(intro_precedence_power)(int res_1, int  res_2)), int(intro_precedence_power)(int res_1, int  res_2));
void  please_enter(void );
int main(void) {
	
	char infix[MAX];
	char postfix[MAX];
	node topPTR = NULL;
	
	fgets(infix, sizeof(infix), stdin);
    int	m = strlen(infix);
	infix[m] = ')';
	memset(postfix, 0, MAX);
	
  
	converting( infix, postfix, &topPTR, check_stack, push_stack, pop, isOperator, precedence, precedence_power);
	out_print(postfix);
	
	puts(" ");
	
return 0;
}
char out_print(char word[]) {
if( word[0]  != '\0' ){
	 	printf( "%c " ,  word[0]    ) ; 
return    out_print(word + 1  )  ;
}
}
void push_stack(node *topPTR, char value) {
	node newPTR = malloc(sizeof(Stack));
	if (newPTR != NULL) {
		newPTR->alpha = value;
		newPTR->nxtPTR = *topPTR;
		*topPTR = newPTR;
	}
	else {
		puts("error");
	}
}
int pop(node *fix) {
int value = (*fix)->alpha;
	node temp = *fix;
	*fix = (*fix)->nxtPTR;
	free(temp);
	return value;
}
char check_stack(node data) {
	return data->alpha;
}
int isOperator(char c) {
	return c == '/' || c == '*' || c == '-' || c == '+'  || c == '^'  ;
}
                                    вычисляет обратною польскою нотацию номер раз
−70
ВЫНЕСЕНИЕ ИНВАРИАНТНОГО КОДА ЗА ПРЕДЕЛЫ ЦИКЛА
Инвариантным называется код, не изменяющийся в ходе выполнения цикла. А раз так, – 
то какой смысл выполнять его в каждой итерации – не лучше ли вынести такой код за пределы цикла?
Рассмотрим следующий пример:
for(a = 0;a  <(b*2);  a++)
printf("%x\n",a*(b/2));
Выражения (b*2) и (b/2) очевидно представляют собой инвариант, и оптимизированный код будет выглядеть так:
tmp_1=b*2;
tmp_2=b/2;
for(a=0;a<tmp_1;a++)
printf("%x\n",tmp_2+=tmp_2);
Это экономит одну операцию деления и две операции умножения на каждую итерацию, что очень и очень неплохо!
Компиляторы Microsoft Visual C++ и WATCOM успешно распознают инвариантный код и выносят его за пределы цикла, 
а вот Borland C++ увы, нет.
                                    Всегда было интересно узнать кто-нибудь чему-нибудь научился на книжках KPNC ?
−49
int minimal_array(int array[], int flag_array[] , int intro_run) {
	int step;
	int end = -1;
	int Minimum = 8;
	for(step = 0; step <= 7; ++step) {
		if( array[step] <= Minimum &&  array[step] >=  1 &&   flag_array[step] ==  1     ) {
			Minimum = array[step];
			end = step;
		}
	}
	if(     intro_run >= (chess * chess - 4) ||      intro_run <=  (chess * chess - 2  ) ) {
		for(step = 0; step <= 7; ++step) {
			if(    array[step] ==  0 &&   flag_array[step] ==  1     ) {
				end = step;
			}
		}
	}
	return end;
}
int   check_point(   int row, int column,  int bord[][chess]	) {
	int p;
	row >= 0 && row <= chess - 1 && column >= 0 && column <= chess -1 && bord[row][column]  == 0 ? (p = 1 ) : (p = 0);
	return p;
}
int cor_hor(int hor_out  ) {
	static	int	  horizont[chess] = {2,1,-1,-2,-2,-1,1,2 };
	return 	   horizont[hor_out];
}
int cor_ver(int ver_out) {
	static	int  	verti[chess] = { -1, -2,-2,-1,1,2,2,1  };
	return  verti[ver_out];
}
int minimum_possible(int cur_Column,int cur_Row, int extro_board[][chess],int run) {
	int   check_point(   int row, int column,  int bord[][chess]	),
	         cor_hor(int in  ),
	         cor_ver(int ni),
	         extro_stop = 0,
	         intro_board[chess][chess] = {0 },
	                                     extro_array[8] = {0 },
	                                             step_row[8] = {0 },
	                                                     step_column[8] = {0 },
	                                                             intro_array[8] = {0 },
	                                                                     extro_number_shift,
	                                                                     extro_shag = 0,
	                                                                     extro_Row  ,
	                                                                     extro_Column ,
	                                                                     cycle_all= 0 ,
	                                                                     step = 0;
	memcpy( intro_board      ,extro_board,  sizeof(intro_board  ));
	for( extro_number_shift = -1; extro_stop <= 8; ) {
		extro_Row += cor_ver(extro_number_shift),extro_Column += cor_hor(extro_number_shift);
		if(check_point(  extro_Row  ,extro_Column ,  intro_board	)  == 1) {
			intro_board[extro_Row][extro_Column]  = ++extro_shag;
			++extro_array[extro_number_shift];
			step_row[extro_number_shift]   =   extro_Row ;
			step_column[extro_number_shift] =  extro_Column ;
		} else {
			++extro_stop;
		}
		extro_Column = cur_Column;
		extro_Row = cur_Row;
		++extro_number_shift ;
	}
	while(cycle_all <=  7)	{
		if(extro_array[cycle_all] == 1) {
			memcpy( intro_board,extro_board,sizeof(intro_board  ));
			intro_board[cur_Row][cur_Column] = 1;
			for( extro_stop = 0,  extro_number_shift  = -1  ; extro_stop  !=   8;) {
				extro_Row +=  cor_ver(extro_number_shift) ,extro_Column += cor_hor(extro_number_shift );
				if(    check_point(  extro_Row  ,extro_Column ,  intro_board	)  == 1) {
					intro_board[extro_Row][extro_Column]  = extro_shag++;
					++intro_array[cycle_all];
				} else {
					extro_stop++;
				}
				extro_Row =     step_row[cycle_all];
				extro_Column  =     step_column[cycle_all] ;
				++extro_number_shift;
			}
		}
		++cycle_all;
	}
	return      	 minimal_array(intro_array   ,extro_array , run )   ;
}
                                    обход доски конем метод варнсдорфа ч.2 набор функций
−49
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#define chess 18
int minimum_possible(int cur_Column,int cur_Row, int extro_board[][chess], int run ),
    check_point(   int row, int column,  int bord[][chess]	),
    cor_hor(int hor_out  ),
    cor_ver(int ver_out);
int main(void) {
	int  step = 1 ,
	     y,x,
	     moveNumber = 1,
	     currentColumn,
	     currentRow,
	     board[chess][chess] = {0 } , p = 1;
	while( p  ) {
		printf("enter the coordinates of the knight y  x: ");
		scanf("%d %d",¤tColumn ,  ¤tRow   );
		if (currentColumn <  0  ||  (currentColumn > (chess - 1)   )  ||  (currentRow  <  0 ||  (currentRow > (chess - 1))    ) )  {
			puts("correct the coordinates of the knight from 0 to 11 for x and y");
		} else {
			p = 0;
		}
	}
	while(  	moveNumber  != -1   )  {
		board[currentRow][ currentColumn]  = step++;
		moveNumber =     minimum_possible(currentColumn,currentRow ,board , step ) ;
		currentRow +=   cor_ver(moveNumber);
		currentColumn +=   cor_hor(moveNumber);
	}
	for(x = 0; x <= chess - 1; x++) {
		puts(" ");
		for(y = 0 ; y <= chess - 1; y++)
			printf("%3d ", board[x][y]);
	}
	return 0;
}
                                    обход доски конем метод варнсдорфа ч.1