日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

九个数的全排列(避免重复出现)

發布時間:2023/12/20 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 九个数的全排列(避免重复出现) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1384

?

使用標準庫里面的next_permutation()函數,這個函數是生成所有比當前的字符串大的字符串,所以最開始經過sort()排序之后,要先打印出當前的字符串。
C++ STL中提供了std::next_permutation與std::prev_permutation可以獲取數字或者是字符的全排列,其中std::next_permutation提供升序、std::prev_permutation提供降序。

兩個代碼本質是一樣的 ?一個從字符串出現,一個從數組

#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<vector> #include<math.h> #include<string> #include<numeric> using namespace std; #define INF 0x3f3f3f3f #define LL long long #define N 106 #define Lson rood<<1 #define Rson rood<<1|1 int main() {char s[21];scanf("%s", s);int lenth = strlen(s);std::sort(s, s + lenth);///將字符串按照字典數排序printf("%s\n", s);///生成所有比當前的字符串大的字符串while (std::next_permutation(s, s + lenth))printf("%s\n",s);return 0; }

#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; int main() {char s[10];int a[10];scanf("%s",s);for(int i=0; s[i]!='\0'; i++)a[i]=s[i]-'0';int l=strlen(s);sort(a,a+l);for(int i=0; i<l; i++)printf("%d",a[i]);printf("\n");while(next_permutation(a,a+l)){for(int i=0; i<l; i++)printf("%d",a[i]);printf("\n");}return 0;}

?

轉載于:https://www.cnblogs.com/a719525932/p/7839685.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的九个数的全排列(避免重复出现)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。