我正在编写一个函数,该函数将指针传递给长度为 4 的数组。这个数组将包含整数0 <= x <= 52
,我想用 da kine 中不在传入数组中的每个整数构造一个长度为 48 的数组。在 python 中,这将是
# just included for specificity
cards = [card for card in deck if card not in hand]
在C中我能做的最好的就是
int i, j, k, found_flag;
int cards[48]; /* int hand[4] is passed in */
k = 0;
for (i = 0; i < 52; i++) {
found_flag = 0;
for (j = 0; j < 4; j++) {
if (i == hand[j]) {
found_flag = 1;
break;
}
}
if (!found_flag) {
cards[k++] = i;
}
}
这对于这种情况是最优的吗?一般来说,是“首选”模式吗?