題目: UVa - 10188 - Automated Judge Script
題目說明
給兩組字串,根據條件分成三種結果。
Input: 每組測資第一行為一整數 n
,代表第一組字串有 n
行,後面 n
行為第一組的字串,再下一行為一整數 m
,代表第二組字串有 m
行,後面 m
行為第一組的字串
Output: 根據條件輸出結果。
解題思路
使用 String 來保存兩組字串,並在讀取的時候加入換行符 '\n'
,之後先比對是否 AC,若不是則取出數字的部分比對是否 PE。
參考解法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include <bits/stdc++.h>
using namespace std;
static auto __ = [] { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); return 0; }();
string process(string& str) { string ret; for (auto& ch : str) if (isalnum(ch) && !isalpha(ch)) ret += ch; return ret; }
int main() { int n, m, x = 0; while ((cin >> n).ignore() && n) { string str, ans, output;
for (int i = 0; i < n; ++i) { getline(cin, str); if (i) ans += '\n'; ans += str; }
(cin >> m).ignore(); for (int i = 0; i < m; ++i) { getline(cin, str); if (i) output += '\n'; output += str; }
cout << "Run #" << ++x << ": ";
if (ans == output) cout << "Accepted\n"; else if (process(ans) == process(output)) cout << "Presentation Error\n"; else cout << "Wrong Answer\n"; } }
|