球上有數字
a.in
3 4
1 3 5
a.out
1111
1113
1115
1131
1133
1135
1151
1153
1155
1311
1313
1315
1331
1333
1335
1351
1353
1355
1511
1513
1515
1531
1533
1535
1551
1553
1555
3111
3113
3115
3131
3133
3135
3151
3153
3155
3311
3313
3315
3331
3333
3335
3351
3353
3355
3511
3513
3515
3531
3533
3535
3551
3553
3555
5111
5113
5115
5131
5133
5135
5151
5153
5155
5311
5313
5315
5331
5333
5335
5351
5353
5355
5511
5513
5515
5531
5533
5535
5551
5553
5555
#include <iostream>
#include <cmath>
using namespace std;
int N,M; //#balls, #draw
int power(int n,int m){
int result=1;
for (int i=0;i<m;i++){result*=n;}
return result;
}
int main () {
cin >> N >> M;
int size=power(N,M);
int *A=new int[M];
int *B=new int[N]; //讀進N顆球的數字
for (int j=0;j<N;j++){
cin >> B[j];
}
for (int i=0;i<size;i++){
int a=i;
for (int j=0;j<M;j++){
A[j]= a%N ;
a = a/N;
}
for (int j=0;j<M;j++){
cout << B[A[M-j-1]];
}
cout << endl;
}
}
沒有留言:
張貼留言