| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
奔溃了,测试数据都过了,但一直WA#include <stdio.h>
#include <string.h>
#include <ctype.h>
char output[16];
int used[33];
int getindex(char c)
{
if(isupper(c)) {
return (c-'A')*2 + 1;
}
else {
return (c-'a')*2 + 2;
}
}
void initused(char *src)
{
int i;
for(i = 1; i <= 32; i++)
{
used[i] = 0;
}
while(*src) {
used[getindex(*src)] += 1;
src++;
}
}
void quicksort(char *src, int l, int r)
{
int p;
int j;
char temp;
if(l < r) {
p = l+1;
j = l+1;
while(j <= r) {
if(getindex(src[j]) < getindex(src[l])) {
temp = src[j];
src[j] = src[p];
src[p] = temp;
p++;
}
j++;
}
temp = src[p-1];
src[p-1] = src[l];
src[l] = temp;
quicksort(src, l, p-1);
quicksort(src, p, r);
}
}
void dfs(char *src, int index, int n)
{
int i;
if(index == n) {
printf("%s\n", output);
return;
}
else {
for(i = 0; i < n; i++)
{
if(used[getindex(src[i])] > 0) {
output[index] = src[i];
used[getindex(src[i])]--;
dfs(src, index+1, n);
output[index] = '\0';
used[getindex(src[i])]++;
while(i+1 < n && src[i+1] == src[i]) {
i++;
}
}
}
}
}
int main()
{
char src[16];
int n;
int testnum;
scanf("%d", &testnum);
while(testnum-- > 0) {
scanf("%s", src);
initused(src);
n = strlen(src);
quicksort(src, 0, n-1);
dfs(src, 0, n);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator