首页 > 代码库 > 简单的排列组合-使用枚举

简单的排列组合-使用枚举

有五种颜色,每次取出三种,要求颜色无重复

 1 #include<stdio.h> 2  3 int main(void) 4 { 5     enum color{blue,red,yellow,purple,black}; 6     enum color i,j,k,pri; 7  8     int n,loop; 9     n=0;10 11     for(i=blue;i<=black;++i)12     {13         for(j=blue;j<=black;++j)14         {15             if(i!=j)16             {17                 for(k=blue;k<=black;++k)18                 {19                     if((k!=i)&&(k!=j))20                     {21                         ++n;22                         printf("%-6d",n);23                         for(loop=1;loop<=3;++loop)24                         {25                             switch(loop)26                             {27                                 case 1:pri=i;28                                        break;29                                 case 2:pri=j;30                                        break;31                                 case 3:pri=k;32                                        break;33                                 default:34                                        break;35                             }36                             switch(pri)37                             {38                                 case blue:printf("%-10s","blue");39                                           break;40                                 case red :printf("%-10s","red");41                                           break;42                                 case yellow:printf("%-10s","yellow");43                                             break;44                                 case purple:printf("%-10s","pueple");45                                             break;46                                 case black:printf("%-10s","black");47                                 default:48                                            break;49                             }50                         }51                         printf("\n");52                     }53                 }54             }55         }56     }57     printf("total : %5d\n",n);58     return 0;59 }

 

简单的排列组合-使用枚举