UVa Problem 10188 Automated Judge Script (自动评测脚本)

// Automated Judge Script (自动评测脚本)
// PC/UVa IDs: 110305/10188, Popularity: B, Success rate: average Level: 1
// Verdict: Accepted
// Submission Date: 2011-05-23
// UVa Run Time: 0.016s
//
// 版权所有(C)2011,邱秋。metaphysis # yeah dot net
	
#include <iostream>
#include <vector>
	
using namespace std;

// AC 的含义是精确匹配。
bool is_ac(vector < string > & s, vector < string > & a)
{
	if (s.size() != a.size())
		return false;
	
	for (int i = 0; i < s.size(); i++)
		if (s[i] != a[i])
			return false;

	return true;
}
	
// 关键是PE的判断,题目含义太隐晦,并没有说清楚,尝试了几种方式才 AC。PE 的含义是答案和提交只要
// 数字顺序相同,尽管它们可能不在同一行,如:
//
// 3
// The answer is: 10
// The answer is: 5
// The answer is: 5
// 3
// The answer is: 1
// The answer is: 05
// The answer is: 5
//
// 像以上情况,应给出 PE 的结果,这个问题导致了多次的 WA 提交。找到提交和答案的所有数字字符,比
// 较得到的数字字符串是否相同,若相同,则为 PE。
bool is_pe(vector < string > & s, vector < string > & a)
{
	string ds, da;
	
	for (int m = 0; m < s.size(); m++)
		for (int n = 0; n < s[m].length(); n++)
			if (isdigit(s[m][n]))
				ds += s[m][n];
				
	for (int m = 0; m < a.size(); m++)
		for (int n = 0; n < a[m].length(); n++)
			if (isdigit(a[m][n]))
				da += a[m][n];
	
	if (ds.length() != da.length())
		return false;
		
	for (int i = 0; i < ds.length(); i++)
		if (ds[i] != da[i])
			return false;
	
	return true;
}
	
int main(int ac, char *av[])
{
	int number;
	vector < string > solution;
	vector < string > answer;
	string line;
	string output[3] = {"Accepted", "Presentation Error", "Wrong Answer"};
	int cases = 0;
	
	while (cin >> number, number)
	{
		solution.clear();
		answer.clear();
		
		// 读入正确答案。
		cin.ignore();
		for (int i = 0; i < number; i++)
		{
			getline(cin, line);
			solution.push_back(line);
		}
		
		// 读入提交。
		cin >> number;
		cin.ignore();
		for (int i = 0; i < number; i++)
		{
			getline(cin, line);
			answer.push_back(line);
		}
		
		// 0 = AC,1 = PE, 2 = WA。
		int status;
		if (is_ac(solution, answer))
			status = 0;
		else if (is_pe(solution, answer))
			status = 1;
		else
			status = 2;
	
		cases++;
		cout << "Run #" << cases << ": " << output[status] << endl;
	}
	
	return 0;
}


你可能感兴趣的:(c,Date,String,vector,脚本,output)