NBUT 1119 Patchouli's Books (STL应用)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                NBUT 1119 Patchouli's Books (STL应用)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                ?
?
題意:
輸入一個序列,每個數字小于16,序列元素個數小于9. 要求將這個序列所有可能出現的順序輸出,而且要字典序。
?
思路:
  先排序,輸出該升序序列,再用next_permutation進行轉變即可,它會調整一次序列,并且字典序是比傳入的序列要大一些,也就是離傳入序列字典序最近的序列。
?
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N=10; 4 char has[50]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; 5 char a[N]; 6 void print(char x) 7 { 8 printf("%c ",x); 9 } 10 int main() 11 { 12 13 //freopen("input.txt", "r", stdin); 14 int n; 15 while(cin>>n) 16 { 17 int tmp; 18 for(int i=0; i<n; i++) 19 { 20 scanf("%d",&tmp); 21 a[i]=has[tmp]; 22 } 23 24 sort(a,a+n); 25 for_each(a,a+n-1,print); 26 printf("%c\n",a[n-1]); 27 28 while( next_permutation(a,a+n)) 29 { 30 for_each(a,a+n-1,print); 31 printf("%c\n",a[n-1]); 32 } 33 } 34 return 0; 35 } AC代碼?
轉載于:https://www.cnblogs.com/xcw0754/p/4538809.html
總結
以上是生活随笔為你收集整理的NBUT 1119 Patchouli's Books (STL应用)的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: acc--›Android无障碍开发手势
 - 下一篇: 清华大学计算机刘云鹏,除北京外,咱省是清