-3
我試圖刷新我的算法技巧並遇到此問題。這裏所說:http://opc.iarcs.org.in/index.php/problems/LEADGAME無法理解要求
我的代碼是:
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char* argv[])
{
int count;
cin >> count;
int winningP = 1; // winning player
int lead = 0; // lead
for (int i=0; i < count; i++)
{
int scoreA, scoreB = 0;
cin >> scoreA >> scoreB;
int l;
if (scoreA > scoreB)
l = scoreA - scoreB;
else
l = scoreB - scoreA;
if (l > lead) // greater lead than what's been processed
{
lead = l;
winningP = scoreA > scoreB ? 1 : 2;
}
}
cout << winningP << " " << lead;
return 0;
}
然而,在網站上,當我提出我的代碼進行評估,它打印出我的程序是給錯誤的答案。我在這裏做錯了什麼?樣本輸入和輸出已被驗證。
你有沒有除了這個例子之外還嘗試過其他的輸入和輸出嗎你確定輸出的格式正確嗎? – Bart
這可能像最後一個缺失的換行符一樣簡單? –
我確實嘗試了其他輸入和輸出,並根據它的行爲方式得到正確答案,除非我錯誤地解釋了問題本身。至於缺失換行符,我嘗試添加,但無濟於事。 – Ishbir