我試圖製作一個紙牌遊戲,我的計劃是製作一個數組,首先保存1-10,然後是JA,然後是顏色,這樣三個不同的數組和不同的變量以及整數字符。從陣列中刪除重複項
但是,我現在的問題仍然存在,我想從數組中刪除重複的問題,但我真的不知道該怎麼做,我已經閱讀了一些事實,但我需要更好的解釋併發出它會看起來代碼明智。
這是我的代碼看起來是迄今:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int arrays[10] = { 1,2,3,4,5,6,7,8,9,10 };
char* color[4] = { "Diamond", "Spade", "Heart", "Clubs" };
int i;
int *number;
srand(time(NULL));
for (i = 0; i < 10; i++) {
number = arrays[rand() % 10];
if (number) { //Its here where i want to remove the duplicates
continue;
}
else {
printf("%d ", number);
}
}
system("pause");
return 0;
}
我將是如何做到這一點的解釋大爲感激,我試圖保持陣列[I]的數值變量,但那麼所有的號碼將被刪除。
在你的例子中,你沒有任何重複,你是什麼意思*刪除重複*?請提供一個例子,例如:'number == 5' - >我希望X發生。 – BeyelerStudios
「從數組中刪除重複項」。您的陣列不包含任何重複項。你能解釋一下你的意思嗎? – kaylum
@JoachimPileborg你是對的,我正在刪除它 – user3085931