Not a difficult problem. Just catenate the lines together and compare the correct and submitted answer will do it well. Unfortunately, the problem statement is misleading: I get WA consistently with a "linesize" of 102, however, it becomes AC when I switch to 110.
Code:
- /*************************************************************************
- * Copyright (C) 2008 by liukaipeng *
- * liukaipeng at gmail dot com *
- *************************************************************************/
- /* @JUDGE_ID 00000 10188 C++ "Automated Judge Script" */
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- using namespace std;
- int const linecount = 100;
- int const linesize = 110;
- int judge(char *correct, int ncorrect, char *submit, int nsubmit)
- {
- int result = 0;
- if (ncorrect != nsubmit) {
- result = 1;
- }
- int p = 0;
- if (result == 0) {
- for (; correct[p] != '/0' || submit[p] != '/0'; ++p) {
- if (correct[p] != submit[p]) {
- result = 1;
- break;
- }
- }
- }
- int c = p, s = p;
- if (result == 1) {
- for (; correct[c] != '/0' || submit[s] != '/0'; ) {
- for (; correct[c] != '/0' && !isdigit(correct[c]); ++c) {}
- for (; submit[s] != '/0' && !isdigit(submit[s]); ++s) {}
- if (correct[c++] != submit[s++]) {
- result = 2;
- break;
- }
- }
- }
- return result;
- }
- int main(int argc, char *argv[])
- {
- #ifndef ONLINE_JUDGE
- filebuf in, out;
- cin.rdbuf(in.open((string(argv[0]) + ".in").c_str(), ios_base::in));
- cout.rdbuf(out.open((string(argv[0]) + ".out").c_str(), ios_base::out));
- #endif
- char const *results[] = {
- "Accepted",
- "Presentation Error",
- "Wrong Answer",
- };
- for (int run = 1; ; ++run) {
- char buf[10];
- cin.getline(buf, 10);
- int ncorrect = atoi(buf);
- if (0 == ncorrect) {
- break;
- }
- char correct[linecount*linesize] = {0};
- for (int i = 0, pos = 0; i < ncorrect; ++i, pos += cin.gcount()-1) {
- cin.getline(correct + pos, linesize);
- }
- cin.getline(buf, 10);
- int nsubmit = atoi(buf);
- char submit[linecount*linesize] = {0};
- for (int i = 0, pos = 0; i < nsubmit; ++i, pos += cin.gcount()-1) {
- cin.getline(submit + pos, linesize);
- }
- int result = judge(correct, ncorrect, submit, nsubmit);
- cout << "Run #" << run << ": " << results[result] << "/n";
- }
- return 0;
- }