50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#include "testlib.h"
|
|
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
bool isSubsequence(string &original, string &sub) {
|
|
int j = 0;
|
|
for (int i = 0; i < original.size() && j < sub.size(); i++) {
|
|
if (original[i] == sub[j]) j++;
|
|
}
|
|
return j == sub.size();
|
|
}
|
|
|
|
int readAns(InStream &stream, string &s1, string &s2) {
|
|
int ans = stream.readInt(0, min(s1.size(), s2.size()), "Common subsequence length");
|
|
stream.readEoln();
|
|
string subsequence;
|
|
if (ans == 0) {
|
|
stream.readEoln();
|
|
subsequence = "";
|
|
} else {
|
|
subsequence = stream.readToken("[a-z]+");
|
|
stream.readEoln();
|
|
}
|
|
stream.readEof();
|
|
|
|
quitif(subsequence.size() != ans, _wa, "sequence has length different from informed");
|
|
quitif(!isSubsequence(s1, subsequence), _wa, "%s is not a subsequence of %s", subsequence, s1);
|
|
quitif(!isSubsequence(s2, subsequence), _wa, "%s is not a subsequence of %s", subsequence, s2);
|
|
|
|
return ans;
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
setName("compare two signed int%d's and check if subsequence given is valid", 8 * int(sizeof(int)));
|
|
registerTestlibCmd(argc, argv);
|
|
|
|
int n = inf.readInt(), m = inf.readInt();
|
|
string s1 = inf.readToken(), s2 = inf.readToken();
|
|
|
|
int ja = readAns(ans, s1, s2);
|
|
int pa = readAns(ouf, s1, s2);
|
|
|
|
if (ja > pa)
|
|
quitf(_wa, "jury has the better answer: jans = %d, pans = %d\n", ja, pa);
|
|
else if (ja < pa)
|
|
quitf(_fail, "participant has the better answer: jans = %d, pans = %d\n", ja, pa);
|
|
|
|
quitf(_ok, "answer is correct");
|
|
} |