简单题
View Code
<
iostream
>
#include
<
cstdio
>
#include
<
cstdlib
>
#include
<
cstring
>
#include
<
algorithm
>
using
namespace
std;
char
st[
20
];
int
num[
20
];
int
n;
int
len;
char
ans[
20
];
bool
cmp(
const
char
&
a,
const
char
&
b)
{
int
x
=
a
–
‘
A
‘
;
int
y
=
b
–
‘
A
‘
;
if
(x
>=
26
)
x
-=
‘
a
‘
–
‘
A
‘
;
if
(y
>=
26
)
y
-=
‘
a
‘
–
‘
A
‘
;
if
(x
!=
y)
return
x
<
y;
return
a
<
b;
}
void
dfs(
int
a)
{
if
(a
==
len)
{
ans[a]
=
‘
\0
‘
;
printf(
“
%s\n
“
, ans);
return
;
}
for
(
int
i
=
0
; i
<
n; i
++
)
if
(num[i]
>
0
)
{
ans[a]
=
st[i];
num[i]
—
;
dfs(a
+
1
);
num[i]
++
;
}
}
int
main()
{
//
freopen(“t.txt”, “r”, stdin);
int
t;
scanf(
“
%d
“
,
&
t);
while
(t
—
)
{
scanf(
“
%s
“
, st);
sort(st, st
+
strlen(st), cmp);
memset(num,
0
,
sizeof
(num));
int
j
=
0
;
len
=
strlen(st);
for
(
int
i
=
0
; i
<
len; i
++
)
if
(st[i]
==
st[j])
num[j]
++
;
else
{
st[
++
j]
=
st[i];
num[j]
=
1
;
}
n
=
j
+
1
;
dfs(
0
);
}
return
0
;
}
转载于:https://www.cnblogs.com/rainydays/archive/2011/06/24/2089132.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110604.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...