# 關於vector C++ Microsoft Visual

１需輸入購買幾組

２電腦亂數選出六個號碼（無需特別號）

３需對照六個號碼是否重覆

４在開一組為中獎號碼

５對照中獎號碼

vector裡在包一vector

2 個已更新項目:

3 個已更新項目:

### 1 個解答

• 1 0 年前
最佳解答

#include <vector>

typedef std::vector<int> LottoNumber;

typedef std::vector<LottoNumber> Numbers;

int main(void)

{

// some code here, srand, initialization....etc

// when creating it

LottoNumber lotto;

for(int i = 0; i < 6; ++i)

lotto.push_back(rand()%60 + 1);

Numbers num;

num.push_back(lotto);

// to access it, for example, there are 6 lotto number in 'num'

// if you want to access the 3rd number in 4th lotto numbers

int value = num[4][3];

// just like accessing double array

// personally, i will use std::map for this question, but that's just me

// by the way, the code is not written in compiler, so might be some

// typing mistakes. but the ideas are there. Good luck

return 0;

}

2007-06-01 06:47:20 補充：

I am sorry, my computer doesn't have Chinese input. But here is things you can do with vector:

(1) typedef std::vector<int> Lotto; // create vector of int

(2) typedef std::vector<Lotto> Numbers; // vector of vector of int

same as std::vector< std::vector<int > >

2007-06-01 06:47:30 補充：

(3) Lotto lotto; // insert 6 numbers

lotto.push_back(0);

lotto.push_back(5);

lotto.push_back(25);

lotto.push_back(16);

lotto.push_back(9);

lotto.push_back(10);

Numbers numbers;

numbers.push_back(lotto); // so there is one set of number, add more

2007-06-01 06:47:35 補充：

(4) To access it:

int fourth = numbers[0][3]; // fourth number in 1st number set

• 登入以對解答發表意見