有序选择L长度排列

http://acm.pku.edu.cn/JudgeOnline/problem?id=3049

参考别人代码写的:

 

#include<stdio.h>



int  L, C;

char list[27], set[27];



void find(int i, int vovel, int ith)

{

	if(ith == L)

	{

		if(vovel)	printf("%s\n", set);

		return ;

	}

	for(; i<=C-L+ith; i++)

	{

		set[ith] = list[i];

		find(i+1, vovel+(set[ith] == 'a' || set[ith] == 'e' || set[ith] == 'i' || set[ith] == 'o' || set[ith] == 'u'), ith+1);

	}

}



int main()

{

	int i, k, arr[123];

	char temp[2];

	while(scanf("%d%d", &L, &C) != EOF)

	{

		for(i='a'; i<='z'; i++)

			arr[i] = 0;

		for(i=0; i<C; i++)

		{

			scanf("%s", temp);

			arr[temp[0]] = 1;

		}

		for(i='a', k=0; i<='z'; i++)

			if(arr[i])

				list[k++] = i;

		set[L] = 0;

		find(0, 0, 0);

	}

	return 0;

}

你可能感兴趣的:(有序)