我試圖解決codechef 這裏的「複製 - 粘貼」規劃問題(https://www.codechef.com/problems/RRCOPY)是我曾嘗試任何人都可以解釋爲什麼我得到'錯誤答案'?
#include <iostream>
using namespace std;
bool isNumberInArray(int array[], int A, int size)
{
bool isFound = false;
for(int i = 0; i < size; i++)
{
if(array[i] == A)
{
isFound = true;
break;
}
}
return isFound;
}
int main()
{
int T, i = 0, A, size = 0, count;
int array[100000];
cin >> T;
while(T--)
{
cin >> size;
count = 0;
i = 0;
while(size--)
{
cin >> A;
if(isNumberInArray(array, A, count) == false)
{
array[i] = A;
count++;
}
i++;
}
cout << count << endl;
}
return 0;
}
誰能告訴我在做什麼錯。 在此先感謝。
你會得到什麼? – ManKeer
錯誤答案@ManKeer – aman19161
我們無法猜測某些代碼有什麼問題。一般來說,花費太多時間。您必須提供輸入,預期輸出和實際輸出。如果他們不可用,那麼我們很可能無法幫助你。 – Dialecticus