不重复排列组合的程序

hongyuan20022003 2008-03-14 09:04:53
比如
a/b/c/e/e 五个字母,形成如下排列:
b-c-d-e
想要得到如下结果:
c-d-b-a
或者
d-b-c-a
总之,相应的位置不能有重复的字母。

如果有abcdef六个字母,形成 bcdef这样的排列,如何得出符合的排列?




...全文
466 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjx2388 2008-03-16
  • 打赏
  • 举报
回复
看起来有点复杂啊

能把题目说的更清楚不???
hongyuan20022003 2008-03-15
  • 打赏
  • 举报
回复
有abcdef六个字母,形成 bcdef这样的排列,有多少排列呢?
fcuandy 2008-03-15
  • 打赏
  • 举报
回复
就是排列组合的问题. n 的阶乘个.
JiangHongTao 2008-03-15
  • 打赏
  • 举报
回复
22L给的是都不能重复的。
下面给出的是不与给定字符串重复,但记录之间还是可以重复。
declare @s varchar(10),@as char(1),@s1 char(1),@i int,@j int 
select @s = 'bcdef',@as = 'a'
declare @t table(s varchar(20))
declare @t1 table(s varchar(20))
select @i = 1,@s = left(@s,len(@s)-1)
while @i <=len(@s)
begin
insert @t1 select substring(@s,@i,1)
set @i = @i +1
end
insert @t select * from @t1 where s <> left(@s,1)
set @i = 1
while @i <len(@s)
begin
insert @t select b.s+a.s from @t1 a,@t b where charindex(a.s,b.s)=0 and a.s <> substring(@s,@i+1,1)
delete @t where len(s)=@i
set @i = @i +1
end
update @t set s = s +@as
select * from @t
/*
s
--------------------
edcba
decba
cdeba
edbca
debca
dbeca
cebda
ebcda
cbeda
*/
chaorenwopashei 2008-03-15
  • 打赏
  • 举报
回复
什么语句啊,怎么看不懂啊
JiangHongTao 2008-03-15
  • 打赏
  • 举报
回复
declare @s varchar(10),@as char(1),@i int
select @s = 'bcdef',@as = 'a'
declare @t table(s varchar(10))
select @i = 1,@s = left(@s,len(@s)-1)
while @i < len(@s)
begin
insert @t select right(@s,len(@s)-@i)+left(@s,@i)+@as
set @i = @i + 1
end
select * from @t
/*
s
----------
cdeba
debca
ebcda
*/
fcuandy 2008-03-15
  • 打赏
  • 举报
回复
不通用, 加一个字母,语句得重写.
-狙击手- 2008-03-14
  • 打赏
  • 举报
回复
declare @t table(col varchar(2))

insert @t select 'b'
insert @t select 'c'
insert @t select 'd'


select a.col + '-'+ b.col+'-'+c.col+'-a'
from @t a,@t b,@t c
where a.col <> b.col and b.col <> c.col and a.col <> c.col

and a.col <> 'b'
and b.col <> 'c'
and c.col <> 'd'


/*

-----------
c-d-b-a
d-b-c-a

(所影响的行数为 2 行)
*/

hongyuan20022003 2008-03-14
  • 打赏
  • 举报
回复
如果有abcdef六个字母,形成 bcdef这样的排列,如何得出符合的排列?
-狙击手- 2008-03-14
  • 打赏
  • 举报
回复
declare @t table(col varchar(2))
insert @t select 'a'
insert @t select 'b'
insert @t select 'c'
insert @t select 'd'


select a.col + '-'+ b.col+'-'+c.col+'-'+d.col
from @t a,@t b,@t c,@t d
where a.col <> b.col and b.col <> c.col and c.col <> d.col and a.col <> c.col and a.col <> d.col and
b.col <> d.col and d.col = 'a'
and a.col <> 'b'
and b.col <> 'c'
and c.col <> 'd'


/*
b-c-d-e

-----------
c-d-b-a
d-b-c-a

(所影响的行数为 2 行)
*/

hongyuan20022003 2008-03-14
  • 打赏
  • 举报
回复
是啊!

-狙击手- 2008-03-14
  • 打赏
  • 举报
回复
这个意思?




已知条件:b-c-d-e

SQL形成 如下结果 :

c-d-b-a
d-b-c-a
hongyuan20022003 2008-03-14
  • 打赏
  • 举报
回复
b-d-c-a

b-c-d-e
第一个字母重合,所以排除!
hongyuan20022003 2008-03-14
  • 打赏
  • 举报
回复
c-d-b-a
或者
d-b-c-a

没有别的
-狙击手- 2008-03-14
  • 打赏
  • 举报
回复
只有两种
相应的位置不能有重复的字母

---






你枚举一些结果来看看
hongyuan20022003 2008-03-14
  • 打赏
  • 举报
回复
只有两种
相应的位置不能有重复的字母。

和b-c-d-e 相比。



求bcdef有多少种排列?




-狙击手- 2008-03-14
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 liangCK 的回复:]
顶一下狙击手.
[/Quote]

别乱顶嘛
liangCK 2008-03-14
  • 打赏
  • 举报
回复
顶一下狙击手.
中国风 2008-03-14
  • 打赏
  • 举报
回复
--最后一个为a的记录:
declare @t table(col varchar(2))
insert @t select 'a'
insert @t select 'b'
insert @t select 'c'
insert @t select 'd'
insert @t select 'e'


select
a.col+'-'+b.col+'-'+c.Col+'-'+d.Col
from
@T a,@T b,@T c,@T d
where
d.Col='a'
and
c.Col<>d.Col
and
b.Col<>d.Col and b.Col<>c.Col
and
a.Col<>b.Col and a.COl<>c.Col and a.COl<>d.Col
-狙击手- 2008-03-14
  • 打赏
  • 举报
回复
declare @t table(col varchar(2))
insert @t select 'a'
insert @t select 'b'
insert @t select 'c'
insert @t select 'd'
insert @t select 'e'

select a.col + '-'+ b.col+'-'+c.col+'-'+d.col
from @t a,@t b,@t c,@t d
where a.col <> b.col and b.col <> c.col and c.col <> d.col and a.col <> c.col and a.col <> d.col and
b.col <> d.col and d.col = 'a'

/*


-----------
b-d-c-a
b-e-c-a
b-c-d-a
b-e-d-a
b-c-e-a
b-d-e-a
c-d-b-a
c-e-b-a
c-b-d-a
c-e-d-a
c-b-e-a
c-d-e-a
d-c-b-a
d-e-b-a
d-b-c-a
d-e-c-a
d-b-e-a
d-c-e-a
e-c-b-a
e-d-b-a
e-b-c-a
e-d-c-a
e-b-d-a
e-c-d-a

(所影响的行数为 24 行)
*/
加载更多回复(6)

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧