2016-12-14 64 views

回答

0

您可以創建另一個數組/使用索引從[0..49]載體,每一個見到的在原數組的值時增加所需的索引:

int arr[100][6]; 
//fill it 

int check[50]; 
for(int i = 0; i < 50; i++) 
    check[i] = 0; 
for(int i = 0; i < 100; i++) 
    for(int j = 0; j < 6; j++) 
     check[arr[i][j]]++; 

//now check has a list of occurences for 0, 1, 2, ..., 49 

至於代碼風格,我會建議從魔術常量像100,50離開,並使用類似

const int max_random = 50; 
const int mat_width = 100; 
const int mat_height = 6; 

此外,對於C++的std ::載體的使用是鼓勵,而不是通常的陣列 - STL只是創造了離開的目的大部分指針/底層操作都是低層次的。