我想解決TopCoder的AdvertisingAgency問題。當我提交此代碼並運行系統測試時,它顯示程序未能通過系統測試。 Hovewer當我從測試面板運行測試時,它傳遞了所有這些測試。你知道問題出在哪裏嗎?AdvertisingAgency - 通過所有測試,但總體失敗[TOPCODER]
源代碼:
您使用unintialized陣列,這是所有UB的#include<iostream>
#include<vector>
using namespace std;
class AdvertisingAgency{
public:
int numberOfRejections(vector<int>requests){
int rejections=0;
bool billboards[100];
for(int request:requests){
if(billboards[request]){
rejections++;
}
else{
billboards[request]=true;
}
}
return rejections;
}
};
不如花時間與這些[C++書籍]的(https://stackoverflow.com/問題/ 388242/the-definitive-c-book-guide-and-list),然後在一些假的_competitive programming_ site上。 – Ron
您正在訪問未被初始化的「廣告牌[請求]」。這是UB。你有什麼問題需要解決/預期的結果是什麼? –