訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容
using System; namespace mytest { class myClass { public static char[] S=new char[3] {'A','B','C'}; public static char[] t=new char[4]; public static int n=3; public static int m=2; public static int m1=m+1; public static void Main(string[] args) { listchar(); combi(1,1); Mchar(); Console.ReadLine(); } public static void listchar() { for( int i = 0; i < S.Length; i++ ) Console.WriteLine("{0}",S[i]); } public static void combi(int a,int b) { if (a==m1) { for(int j=1;j<=m;j++) Console.Write("{0}",t[j]); Console.Write("\n"); } else { for(int k=b;k<=n-m+a;k++) { t[a]=S[k-1]; combi(a+1,k+1); } } } public static void Mchar() { for(int g=0;g<S.Length;g++) Console.Write("{0}",S[g]); Console.Write("\n"); } } }
void perm(char a[],int i,int n){ int j; char temp; if(i==n) { for(j=0;j<n;j++){printf("%c",a[j]);} printf("\n"); } else{ for(j=i;j<=n;j++) { temp=a[i-1];a[i-1]=a[j-1];a[j-1]=temp; perm(a,i+1,n); temp=a[i-1];a[i-1]=a[j-1];a[j-1]=temp; } } } void main() { char a[]={'a','i','d','s'}; perm(a,1,4); }