目錄:
所有的範例題目都是a+b問題
Input :
3 4
Output :
7
計分方式:checker會輸出一個介於0到1之間的浮點數,0表示沒有拿到分數,1表示完全拿到此題子測資的分數,0.5表示拿到一半子測資的分數,以此類推。
設定步驟:
Output evalution
改成Outputs are compared by a comparator
編譯指令:g++ checker.cpp -o checker -static
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
ifstream input(argv[1]);
ifstream correct_output(argv[2]);
ifstream user_output(argv[3]);
int userans, ans;
user_output >> userans;
correct_output >> ans;
if (userans == ans) cout << 1.0 << '\n';
else cout << 0.0 << '\n';
}
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + b << '\n';
}
管理員需要上傳一份Code(Loader Code),judge會把參賽者的Code和Loader Code合併,再去編譯及執行,因此參賽者只需要實作特定的function即可。
設定步驟:
Compilation
改成Submissions are compiled with a grader
Batch Type
:grader.cpp
Communication Type
:stub.cpp
#include <bits/stdc++.h>
using namespace std;
int add(int x, int y);
int main() {
int a,b;
cin >> a >> b;
cout << add(a, b) << '\n';
}
#include <bits/stdc++.h>
using namespace std;
int add(int a, int b){
return a + b;
}
Batch Type:
Communication Type:
讓用戶的程式碼跟judge互動,一來一往,可防止參賽者使用離線算法。
要記得設定Time Limit否則會無法編譯。
Time Limit
為1
Task Type
為Communitation
Number of Processes
為1
User I/O
為 User processes read from stdin and write to stdout
一樣a+b問題,但參賽者不知道有幾次查詢,計算完並輸出結果後judge才會告訴你下一組查詢。
Input :
2
3 4
34587378934534 32452384572389
Output :
7
67039763506923
編譯指令:g++ manager.cpp -o manager -static
manager最後會需要輸出一個0到1之間的數,用法跟checker一樣用來計算分數。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, char **argv) {
ofstream to_user(argv[2]);
ifstream from_user(argv[1]);
int n;
cin >> n;
double score = 0;
for (int i = 1; i <= n; i++) {
ll a, b, userans;
cin >> a >> b;
to_user << a << ' ' << b << endl;
from_user >> userans;
ll ans = a + b;
score += (userans == ans) * 1.0 / n;
}
cout << score << '\n';
to_user.close();
from_user.close();
}
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
long long a, b;
while(cin >> a >> b){
cout << a + b << endl;
}
}
Communication Type
一定要使用endl
或flush
來清空緩衝區。