Created
April 26, 2018 01:12
-
-
Save goodjack/5fa19e9c25a21f53a53705304ec21cb5 to your computer and use it in GitHub Desktop.
禮券問題
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int amount; | |
cout << "請輸入商品數"; | |
cin >> amount; | |
int products[amount]; | |
cout << "請輸入商品金額(以空白隔開)"; | |
for (int i = 0; i < amount; i++) { | |
cin >> products[i]; | |
} | |
cout << "二的 " << amount << " 次方是 " << pow(2, amount) << endl; | |
int buyItOrNot[(int)pow(2, amount)][amount] = {0}; // 陣列初始化 | |
for (int x = 0; x < amount; x++) { | |
int change = pow(2, x); | |
int nowInsert = 1; | |
for (int y = 0; y < pow(2, amount); y++) { | |
if (y % change == 0) { | |
nowInsert = (nowInsert == 0) ? 1 : 0; | |
} | |
buyItOrNot[y][x] = nowInsert; | |
cout << buyItOrNot[y][x] << " "; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment