标题:算法:对几个字母排序
只看楼主
yincuihuang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-10-11
 问题点数:0 回复次数:3 
算法:对几个字母排序
对几个字母排序
这是一个算法题:
根据输入的几个数,对其进行排列
要求没重复
如:输入:a,b,c
输出:
a,b,c
a,c,b
b,a,c
b,c,a
c,a,b
c,b,a
要求写个程序实现它
搜索更多相关主题的帖子: 算法 字母 
2008-10-11 18:39
duanchangren
Rank: 1
等 级:新手上路
威 望:1
帖 子:252
专家分:0
注 册:2008-7-26
得分:0 
摆序还是摆列
说清楚
2008-10-11 23:19
guang
Rank: 4
来 自:广东深圳
等 级:贵宾
威 望:13
帖 子:1414
专家分:285
注 册:2006-4-3
得分:0 
就是数学中的C3取2那种吧,用递归实现吧

不相信未作牺牲竟先可拥有,只相信靠双手找到我的欲求!!
我的博客:http://liao5930.blog.
2008-10-11 23:26
duanchangren
Rank: 1
等 级:新手上路
威 望:1
帖 子:252
专家分:0
注 册:2008-7-26
得分:0 
static void Main(string[] args)
        {
            string[] array ={"1","2","3","4","5"};
            List<ArrayList> list1 = new List<ArrayList>();
            List<ArrayList> list2 = new List<ArrayList>();

            list1.Add(new ArrayList());
            list1[0].Add(array[0]);
            for(int count=0;count<array.Length-1;count++)
            {
                list2.Clear();
                for (int i = 0; i < list1.Count; i++)
                {
                    list1[i].Add(array[count + 1]);
                    #region
                    for (int j = 0; j < list1[i].Count; j++)
                    {
                        ArrayList arraylist = new ArrayList();
                        for (int d = 0; d < list1[i].Count; d++)
                        {
                            if (j == d)
                                arraylist.Add(list1[i][(list1[i].Count) - 1]);
                            else if (d == list1[i].Count - 1)
                                arraylist.Add(list1[i][j]);
                            else
                                arraylist.Add(list1[i][d]);
                        }
                        list2.Add(arraylist);
                    }
                    #endregion
                }
                list1.Clear();
                for (int a = 0; a < list2.Count; a++)
                {
                    ArrayList arraylist = new ArrayList();
                    for (int b = 0; b < list2[a].Count; b++)
                    {
                        arraylist.Add(list2[a][b]);
                    }
                    list1.Add(arraylist);
                }
            }
            for (int a = 0; a < list2.Count; a++)
            {
                Console.Write((a + 1)+"\t\t");
                for (int b = 0; b < list2[a].Count; b++)
                {
                    Console.Write(list2[a][b]);
                }
                Console.WriteLine();
            }
            Console.Read();
        }
2008-10-12 01:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-237652-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.370543 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved