头上蛇胆疮好了神经痛:一道程序题

来源:百度文库 编辑:高考问答 时间:2024/05/06 06:11:58
Online Judge
Time Limit : 1000 ms Memory Limit : 32768 K Output Limit : 1024 K
Total Submission(s) : 243 Accepted Submission(s) : 52

Problem Description

Ignatius is building an Online Judge, now he has worked out all the problems except the Judge System. The system has to read data from correct output file and user's result file, then the system compare the two files. If the two files are absolutly same, then the Judge System return "Accepted", else if the only differences between the two files are spaces(' '), tabs('\t'), or enters('\n'), the Judge System should return "Presentation Error", else the system will return "Wrong Answer".

Given the data of correct output file and the data of user's result file, your task is to determine which result the Judge System will return.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case has two parts, the data of correct output file and the data of the user's result file. Both of them are starts with a single line contains a string "START" and end with a single line contains a string "END", these two strings are not the data. In other words, the data is between the two strings. The data will at most 5000 characters.

Output

For each test cases, you should output the the result Judge System should return.

Sample Input

4
START
1 + 2 = 3
END
START
1+2=3
END
START
1 + 2 = 3
END
START
1 + 2 = 3

END
START
1 + 2 = 3
END
START
1 + 2 = 4
END
START
1 + 2 = 3
END
START
1 + 2 = 3
END

Sample Output

Presentation Error
Presentation Error
Wrong Answer
Presentation Error

Author

Ignatius.L
L_o_o_n_i_e 可能没有做过ACM的题目,对输入输出有所误解。算法我还未看过,有空再研究一下。

输入数据必须按格式写在一个数据文件里,例如叫case4.txt
START和END必须大写且无空白,因为它们是控制行。
把下面程序存入judge.c 编译后(我用MS VC++编译器试过了)
运行命令:
judge.exe case4.txt
======================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

FILE *fin;
main(int argc, char *argv[])
{
char namein[40];
int T;
int i,j,k;
char str[8];
int N1,N2;
unsigned char tmp;
unsigned char a[5000],b[5000];
char *buff;

if (argc < 2) {
printf("\007Usage:%s file_name.txt\n",argv[0]);
printf("For example: %s case4.txt\n",argv[0]);
exit(1);
};
strcpy(namein,argv[1]);
if ( (fin= fopen(namein, "r")) ==NULL ) {
fprintf(stderr, "Can't open input file %s \n", namein);
exit(1);
};

buff = (char *) malloc(5000 * sizeof (char));
if ( !buff ) {
printf("\007No enough space to alloc\n"); exit(1);
}

if ( fgets(buff,5000,fin) !=NULL){
sscanf(buff,"%d",&T); // read the number of cases
};

for (k=0;k<T;k++)
{
// read to first START
while (fgets(buff,5000,fin) !=NULL){
sscanf(buff,"%s",&str[0]);
if (strncmp(&str[0],"START",5) == 0) break;
};

// read file-1
N1 = 0;
while (fgets(buff,5000,fin) !=NULL){
sscanf(buff,"%s",&str[0]);
if (strncmp(&str[0],"END",3) == 0) break;

for (j=0;j<5000;j++){
sscanf(buff+j,"%c", &tmp);
a[N1] = tmp;
if (a[N1] == '\n') {N1 = N1 + 1; break; };
N1 = N1 + 1;
}
strcpy(&buff[0],"\0");
};

// read to second START
while (fgets(buff,5000,fin) !=NULL){
sscanf(buff,"%s",&str[0]);
if (strncmp(&str[0],"START",5) == 0) break;
};

// read file-2
N2 = 0;
while (fgets(buff,5000,fin) !=NULL){
sscanf(buff,"%s",&str[0]);
if (strncmp(&str[0],"END",3) == 0) break;

for (j=0;j<5000;j++){
sscanf(buff+j,"%c", &tmp);
b[N2] = tmp;
if (b[N2] == '\n') {N2 = N2 + 1; break; };
N2 = N2 + 1;
}
strcpy(&buff[0],"\0");
};

// comp 2 files:
if (N1 == N2) {
for (i=0;i < N1;i++) {
if (a[i] != b[i]) goto Lab_comp_2;
};
} else {goto Lab_comp_2;};

printf("Case %d Accepted !\n",k+1);
goto Lab_next_case;

Lab_comp_2:;
// filter and comp
j=0;
for (i=0;i<N1;i++){
a[j]=a[i];
if (a[i] != ' ' && a[i] != '\t' && a[i] != '\n') j = j + 1;
};
N1 = j+1;

j=0;
for (i=0;i<N2;i++){
b[j]=b[i];
if (b[i] != ' ' && b[i] != '\t' && b[i] != '\n') j = j + 1;
};
N2 = j+1;

if (N1 == N2) {
for (i=0;i<N1;i++) {
if (a[i] != b[i]) goto Lab_comp_3;
};
};
printf("Case %d Presentation Error!\n",k+1);
goto Lab_next_case;
Lab_comp_3:;
printf("Case %d Wrong Answer!\n",k+1);
Lab_next_case:;
};
exit(0);
}
==========================================
程序原理:
用fgets() 读一行,分析一行。
第一行是案件个数。
每个案件有两个数据块。
数据块开始行是START.结束行是END。
每个块的行数不固定,每行字符数不固定,但每个块不超过5000字。
所以数组大小用5000,行暂存器buff大小用5000.
每读完一个案件比较两个数据块。
如果字数个数相等,且每个对应字相同,则打印“接受”,处理下一案件。
如果字数个数相等,且对应字有不同,或如果字数不相等,则作过滤处理,处理后再比较。

例子的答案是:
Case 1 Presentation Error!
Case 2 Presentation Error!
Case 3 Wrong Answer!
Case 4 Accepted !

输入文件:
type case4.txt:
4
START
1 + 2 = 3
END
START
1+2=3
END
START
1 + 2 = 3
END
START
1 + 2 = 3

END
START
1 + 2 = 3
END
START
1 + 2 = 4
END
START
1 + 2 = 3
END
START
1 + 2 = 3
END

class operation{
public:
enum ANSWER{ SUCCESS, PRESTE, WRONG };
public:
operation( string & data ) : _data(data) {}

const operation& operator += ( const string & data )
{
_data += data;
return *this;
}

ANSWER operator ==(const operation & oper ) const
{
if ( _data == oper._data )
return SUCCESS;

operation new_self=*this;
operation new_oper=oper;

if ( new_self._trim() == oper._trim() )
return PRESTE;

return WRONG;
}

private:
const operation& _trim()
{
char list[]={\' \',\'\\t\',\'\\n\'};

for( string::iterator itor=_data.begin(); itor != _data.end(); )
{
int flag=0;
for( int i = 0; i < sizeof(list)/sizeof(char); i++ )
{
if ( *itor == list[i] )
{
flag++;
itor = _data.earse( itor );
break;
}
}

if ( !flag ) itor++;
}

return *this;
}
private:
string _data;
};

刷分的小朋友们 能不能少发几个字 我的网速没你们快 开个页面很痛苦

在线法官
期限 : 1000个 ms 记忆界限 : 32768 K 输出界限 : 1024 K
总服从 (s): 243 一般承认的服从 (s): 52

问题描述

圣伊格内修斯正在建筑一个在线法官, 现在他已经解决所有的问题除法官系统。 系统必须读来自正确的输出数据文件和使用者的结果文件,然后系统比较二个文件。如果二个文件是 absolutly 相同的, 然后被接受的法官系统回返,别的如果在二个文件之间的唯一不同是空间 (''), 定位键 ('\t'), 或进入 ('\ n'),法官系统应该归还 " 发表错误 ",否则系统将会归还 " 错误的答案 " 。

给正确输出的数据文件而且给使用者的结果文件的数据, 你的工作是决定哪一产生法官系统将会归还。

输入

输入包含一些测试情形。 输入的第一条线是测试情形的数字单一完整的事物 T 。 T 测试情形跟随。
每个测试情形有二个部份, 正确输出的数据文件和使用者的数据结果文件。 两者都他们是有一条单一线的开始用一条单一线包含线 " 开始 " 和结束包含线 " 结束 ",这二线不是数据。 换句话说,数据是在二线之间。 数据最多决意 5000个个性。

输出

对于每个测试情形, 你应该输出结果法官系统应该归还。

。。。

太悬啦!

看不懂