准备工作:
创建 input.txt 放测试数据
创建 expect.txt 放预期结果
例题: https://codeforces.com/problemset/problem/50/A
input.txt
2 4
3 3
expect.txt
4
4
编译命令
g++ main.cpp -std=c++17 -Wall -DTEST
输出结果
完美通过了,那么可以直接提交了
#include <iostream>
#include <utility>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <fstream>
using namespace std;
//#define TEST
#ifdef TEST
string dir = "./";
string inputFile = dir + "input.txt";
string outputFile = dir + "output.txt";
string expectFile = dir + "expect.txt";
ifstream in(inputFile);
ofstream out(outputFile);
ifstream output(outputFile);
ifstream expect(expectFile);
#else
istream &in = cin;
ostream &out = cout;
#endif
string emptyStr = "nullptr";
class Prepare {
public:
Prepare() {
prepare();
}
static void prepare() {
#ifdef TEST
if (!in.is_open()) {
cout << "empty input file" << endl;
exit(-1);
}
if (!expect.is_open()) {
cout << "empty expect file" << endl;
exit(-1);
}
#endif
}
};
class Check {
public:
~Check() {
// compare
#ifdef TEST
for (int i = 1; !output.eof(); ++i) {
if (output.eof()) {
break;
}
string l, r;
getline(output, l);
getline(expect, r);
while (!l.empty() && l.back() == ' ') {
l.pop_back();
}
while (!r.empty() && r.back() == ' ') {
r.pop_back();
}
if (l.empty() && r.empty()) {
break;
}
if (l == emptyStr) {
break;
}
if (l == r) {
cout << "case: " << i << " pass" << endl;
} else if (l != r) {
cout << "case: " << i << "wrong " << "output[" << l << "], while expect[" << r << "]" << endl;
continue;
}
}
#endif
}
};
static Prepare pre;
static Check check;
void solve(int m, int n) {
if (m % 2 == 0 || n % 2 == 0) {
out << m * n / 2 << endl;
return;
}
out << (n - 1) / 2 * m + m / 2 << endl;
}
int main() {
// need rewrite input
int m, n;
while (in >> m >> n) {
solve(m, n);
}
}