Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Ветеран


Сообщения: 1404
Благодарности: 135

Профиль | Отправить PM | Цитировать


Вчера просмотрел свой код и понял, что очень СИЛЬНО проглючил и неэффективно решил задачу.
Хотя функция recursivetransposition была написана корректно, но применить ее надо было к изначально заданному массиву.

Код: Выделить весь код
#include <stdio.h>

#define N 2
#define MAX 10
#define SIZE 10


int recursivetransposition(char k[],char temp[],int index); 
void print (char temp[]);                     /*Распечатка*/
int ismatch(char temp[]);
int isall(char k[], char temp[]);

void main(){
	char temp[SIZE];
	char k[N]={'m','a'}; /*Заданный массив*/
	recursivetransposition(k, temp, 0);
}

int recursivetransposition(char k[],char temp[],int index){
	int i;
	for (i = 0; i < N; i++){
			temp[index] = k[i];
			if ( index == SIZE-1 )
			{			
				if (ismatch(temp))
					if(isall(temp,k))
						print(temp);
			}			
			else {
				index++;
				index=recursivetransposition(k, temp, index);/**/				
			}
		}
	
	index--;
	return(index);
	}

void print (char temp[]){
	int j;
	for (j=0; j<SIZE; j++)
		{
		printf ("%c", temp[j]);
		}
	printf ("\n");

}

int ismatch(char temp[]){
	int j;
	int test=0;
	for(j=1; j<SIZE;j++)
		if (temp[j] != temp[j-1])
			test=0;
		else
		{
			test++;
			if (test>=MAX)
				return(0);
		}
		return(1);
		}


int isall(char k[], char temp[]){
	int i,j,est;
	for(i=0;i<N;i++){
		for(est=0, j=0;j<SIZE;j++){
			if(temp[i]==k[j])
				est=1;
		}
		if (est==0)
			return(0);
		}
	return(1);	
}

Последний раз редактировалось mrcnn, 18-02-2005 в 02:22.


Отправлено: 02:16, 18-02-2005 | #15