1 solutions

  • 2
    @ 2024-11-30 14:55:06
    #include<bits/stdc++.h>
    using namespace std;
    int n;
    char a[15];
    //写一个判断是否重复的函数 
    bool is(string n,char m){
    	for(int i=0;i<n.size();i++) if(n[i]==m) return false;
    	return true;
    }
    //开始递归 
    void A(string w){
    	if(w.size()==n){
    		//满足条件就输出 
    		for(int i=0;i<n;i++) cout<<"    "<<w[i];
    		cout<<"\n";
    	}
    	//否则继续 
    	else for(int i=0;i<n;i++)
    		if(is(w,a[i])) A(w+a[i]);
    }
    int main(){
    	cin>>n;
    	for(int i=0;i<n;i++) a[i]=i+1+'0';//将数字转字符 
    	A("");
    	return 0;
    }
    
    • 1

    Information

    ID
    685
    Time
    1000ms
    Memory
    125MiB
    Difficulty
    2
    Tags
    # Submissions
    2
    Accepted
    2
    Uploaded By