您的位置:首页 > 其它

南阳 oj 擅长排列的小明 题目19

2015-07-31 08:16 363 查看

next 以及pre 函数的用法

/article/3583994.html



#include <stdio.h>  
 #include <string.h>  
 #include <algorithm>  
 char a[10]={'1','2','3','4','5','6','7','8','9','\0'};//给定一个已排列的数组  
using namespace std;  
 int main()  
 {  
   int t,n,m;  
   char b[10],c[10],c1[10];  
   scanf("%d",&t);  
   while(t--)  
  { 
       scanf("%d%d",&n,&m);
       strcpy(c,a);
    c[m]='\0'; 
    printf("%s\n",c);     
       while(next_permutation(a,a+n))//将a[0]到a
全排列  从小到大 
      {  
           strcpy(c1,a);  
           c1[m]='\0';//取前m个元素
          if(strcmp(c1,c)!=0)
     {
      printf("%s\n",c1);
      strcpy(c,c1);
        }    
       }
   }  
   return 0;  
 }



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: