首页 > 其他 > 详细

全排列

时间:2017-12-04 14:40:31      阅读:168      评论:0      收藏:0      [点我收藏+]

#include <stdio.h>

int t[7];
char s[7];
int n = 0;

void permutation(int i)
{
int k;

// a~z的ASCII码在97到122之间
for(k = 97; k < 123; k++)
{
if(t[k])
{
t[s[i] = k]--;
permutation(i + 1);
t[k]++;
}
}

// 只有n个字母全部排好了才输出
n - i || puts(s);
}

int main()
{
int i;

puts("Please Input letter sequence: ");
gets(s);

// t[]记录每个字母的出现频率
// n为待排序列的长度
for(i = 0; s[i] != ‘\0‘; i++)
{
t[s[i]]++;
n++;
}

puts("排列 result: ");
permutation(0);

return 0;
}

全排列

原文:http://www.cnblogs.com/dourcer/p/7976838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!