看输出格式里有说本题使用 SPJ,会不会是标签忘记加了。恳请管理大大查看一下。
如果尚未有 spj 程序,我也有写一份 spj。不介意的话麻烦加到题目中吧。
#include "testlib.h"
std::string inS, ouS, anS;
inline bool checkFormat() {
int n = (int) ouS.size(), m = inS.size();
if (n > 3000) return false;
if (n < m) return false;
for (int i = 0; i < n; ++i) {
if (ouS[i] >= '0' && ouS[i] <= '9') continue;
if (ouS[i] == '+' || ouS[i] == '=') continue;
return false;
}
if (ouS[0] == '+') return false;
if (ouS[n - 1] == '+') return false;
for (int i = 1; i < n; ++i)
if (ouS[i] == '+' && ouS[i] == ouS[i - 1]) return false;
int j = 0;
for (int i = 0; i < n; ++i) {
if (ouS[i] == '+') continue;
if (j >= m) return false;
if (ouS[i] != inS[j]) return false;
j++;
}
if (j != m) return false;
return true;
}
inline bool checkMinimum() {
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < (int) ouS.size(); ++i)
if (ouS[i] == '+') cnt1++;
for (int i = 0; i < (int) anS.size(); ++i)
if (anS[i] == '+') cnt2++;
return cnt1 == cnt2;
}
inline int getValue(int l, int r) {
if (l + 4 <= r) return -999999999;
int x = 0;
for (int i = l; i <= r; ++i)
x = x * 10 + ouS[i] - '0';
return x;
}
inline bool checkSum() {
long long s = 0, b = 0;
int n = (int) ouS.size();
for (int i = n - 1; i >= 0; --i) {
if (ouS[i] == '=') {
b = getValue(i + 1, n - 1);
break;
}
}
int pre = -1;
for (int i = 0; i < n; ++i) {
if (ouS[i] == '+' || ouS[i] == '=') {
s += getValue(pre + 1, i - 1);
pre = i;
if (ouS[i] == '=') break;
}
}
return s == b;
}
int main(int argc, char *argv[]) {
registerTestlibCmd(argc, argv);
inS = inf.readToken();
ouS = ouf.readToken();
anS = ans.readToken();
if (checkFormat() == false) quitf(_wa, "Wrong Answer[1]");
if (checkMinimum() == false) quitf(_wa, "Wrong Answer[2]");
if (checkSum() == false) quitf(_wa, "Wrong Answer[3]");
quitf(_ok, "Accepted");
return 0;
}