Untitled

                Never    
C
       
/*1.掃進來存在given_list,計算list長度,用bubblesort的方式排好(list())
2.使用遞迴的function (perm)
a.每個level固定position的位子(for password),存given_list的值進去
b.given_list設定start和end,表示可以放進password的值(因為不能放到position在ascii排序前面的值
3.每當password被存到4或4以上就print出來(用position控制,從0print到position)
4.注意當password[0]不是given_list[len-4]時後面接“,”,是的時候後面接“\n

疑慮:它不應該繼續輸下去所以這個應該是對的吧!但還是覺得怪怪的
*/

#include <stdio.h>
#include <string.h>

char given_list[20];        //use given_list to store the input
char password[20];          //use passward to store the output
int len;

void list();
void perm(int pos,int start,int end);
//pos is for the currant position of password[]
//start~end is for the range of given_list[]

int main(void){
    scanf("%s",given_list);
    len=strlen(given_list);
    list();
    perm(0,0,len-1);
    return 0;
}

void perm(int pos,int start,int end){
    int i;
    //basic step
    if(pos>=4 && pos<=len){
        for(int j=0;j<pos;j++)
            printf("%c",password[j]);
        if(password[0]!=given_list[(len-4)])
            printf(",");
        else
            printf("\n");
    }
    //recursive step
    for(i=start;i<=end;i++){
        password[pos]=given_list[i];
        //printf("pos:%d %c ",pos,password[pos]);
        perm(pos+1,i+1,end);
    }
}

/*******bubble sort*******/
void list(void){
    char temp;
    for(int i=0;i<len-1; i++) {
            for (int j=0; j<len-1-i;j++) {
                  if (given_list[j]>given_list[j+1]) {
                       temp=given_list[j];
                        given_list[j]=given_list[j + 1];
                       given_list[j+1]=temp;
                  }
            }
      } 
}

Raw Text