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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

STL训练 HDU - 1716 Ray又对数字的列产生了兴趣:

發布時間:2023/12/15 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 STL训练 HDU - 1716 Ray又对数字的列产生了兴趣: 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

HDU - 1716 Ray又對數字的列產生了興趣:

現有四張卡片,用這四張卡片能排列出很多不同的4位數,要求按從小到大的順序輸出這些4位數。
Input
每組數據占一行,代表四張卡片上的數字(0<=數字<=9),如果四張卡片都是0,則輸入結束。
Output
對每組卡片按從小到大的順序輸出所有能由這四張卡片組成的4位數,千位數字相同的在同一行,同一行中每個四位數間用空格分隔。
每組輸出數據間空一行,最后一組數據后面沒有空行。
Sample Input 1 2 3 4
1 1 2 3
0 1 2 3
0 0 0 0
Sample Output
1234 1243 1324 1342 1423 1432
2134 2143 2314 2341 2413 2431
3124 3142 3214 3241 3412 3421
4123 4132 4213 4231 4312 4321
1123 1132 1213 1231 1312 1321
2113 2131 2311
3112 3121 3211
1023 1032 1203 1230 1302 1320
2013 2031 2103 2130 2301 2310
3012 3021 3102 3120 3201 3210

思路,使用全排列next_permat 或通過一個不斷排列組合用

#include<iostream> #include<cstdio> #include<cstring> #include<map> #include<set> #include<algorithm> using namespace std; set<int> mx; int main() {int a[5];int sb=0;for(;;){mx.clear();int multi;for(int i=1;i<5;i++){cin>>a[i];}if(a[1]==0&&a[2]==0&&a[3]==0&&a[4]==0) break;if(sb)cout<<endl;sb++;for(int i=1;i<5;i++){for(int j=1;j<5;j++){if(i==j) continue;for(int k=1;k<5;k++){if(j==k||i==k) continue;for(int l=1;l<5;l++){if(k==l||l==j||l==i) continue;multi=a[i]*1000+a[j]*100+a[k]*10+a[l];if(multi>999) mx.insert(multi);}}}}set<int>::iterator poi,p2;p2=mx.begin();int xa=0;for(poi=mx.begin();poi!=mx.end();poi++){p2++;if(xa) cout<<' ';xa++;cout<<*poi;if(*p2/1000!=*poi/1000){cout<<endl;xa=0;}}}return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<map> #include<set> #include<algorithm> using namespace std; int main() {char a[4]={0};int x=0;for(;;){for(int i=0;i<4;i++){cin>>a[i];}sort(a,a+4);char w=a[0];if(a[0]=='0'&&a[1]=='0'&&a[3]=='0'&&a[2]=='0') break;if(x) cout<<endl;x++;int qt=0;int lasta0=-1;bool flag2=true;do {if(a[0]=='0')continue;if(flag2)flag2 = false;else if(a[0] == lasta0) cout<<' ';else cout<<endl;cout<<a[0]<<a[1]<<a[2]<<a[3];lasta0 = a[0];} while(next_permutation(a, a +4));cout<<endl;}return 0; }

總結

以上是生活随笔為你收集整理的STL训练 HDU - 1716 Ray又对数字的列产生了兴趣:的全部內容,希望文章能夠幫你解決所遇到的問題。

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