芝士蛋糕


私信TA

用户名:dotcpp0677002

访问量:421

签 名:

等  级
排  名 7333
经  验 1271
参赛次数 0
文章发表 6
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

注意事项:两种代码,第二种交换的代码由于最终打印顺序不同通过不了此题

参考代码:

#include <stdio.h>

#include <string.h>

#include <stdbool.h>

bool judge[26];

char s[26];

char temp[26];

int lens;

void arrange(int index){

int j;

if(index==lens){

printf("%s\n",temp);

} else{

for(j=0;j<lens;j++){

if (judge[j]==1){

temp[index]=s[j];

judge[j]=0;

arrange(index+1);

judge[j]=1;

}

}

}

}

int main(){

//char s[26];

int i;

scanf("%s",s);

lens=strlen(s);

for(i=0;i<lens;i++){

judge[i]=1;

}

arrange(0);

}


第二种

#include <stdio.h>

#include <string.h>

char s[26];

int lens;

void swap(char *a,char *b){

char t;

t=*a;

*a=*b;

*b=t;

}

void arrange(int st,int e ){

int i,j;

if(st==e) {

printf("%s\n",s);

}

else{

for(i=st;i<lens;i++){

swap(&s[st],&s[i]);

//printf("%s\n",s);

arrange(st+1,e);

swap(&s[i],&s[st]);

}

}

}

int main(){

//int lens;

scanf("%s",s);

lens=strlen(s);

//printf("%d",lens);

arrange(0,lens-1);

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区