HDU-1073 Online Judge(字符串)

本文详细解析了一道关于在线判题系统的编程题,探讨了如何比较两个文件的内容,忽略空格、制表符和换行符,以判断提交的答案是否正确。通过C++代码示例,介绍了处理字符串和实现判题逻辑的方法。

题目回顾HDU-1073):

Online Judge

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
6
8
 
Sample Output
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
 
源码与解析
字符串水题,不过温故一下输入带空格换行的字符串。
#include<iostream>
#include<string>
using namespace std;

string start;
string s;

string s1,s2;

int compare(){
	if(s1==s2){
		return 1;
	}
	string ss1="";
	string ss2="";
	for(int i=0;i<s1.length();i++){
		if(s1[i]!=' '&&s1[i]!='\n'&&s1[i]!='\t'){
			ss1+=s1[i];
		}
	} 
	for(int i=0;i<s2.length();i++){
		if(s2[i]!=' '&&s2[i]!='\n'&&s2[i]!='\t'){
			ss2+=s2[i];
		}
	} 
	if(ss1==ss2){
		return 2;
	}else{
		return 3;
	}
}

int main(){
	int n;
	cin>>n;
	while(n--){
		s1="";
		s2=""; 
		cin>>start;
		while(getline(cin,s)){
			if(s!="END"){
				s1+=s;
				s1+='\n'; 
			}else{
				break;
			}
		}
		cin>>start;
		while(getline(cin,s)){
			if(s!="END"){
				s2+=s;
				s2+='\n'; 
			}else{
				break;
			}
		}	
		switch(compare()){
			case 1:
				cout<<"Accepted"<<endl;
				break; 
			case 2:
				cout<<"Presentation Error"<<endl;
				break;
			case 3:
				cout<<"Wrong Answer"<<endl;
				break;
		}
	}
	return 0;
} 

  

 

转载于:https://www.cnblogs.com/orangecyh/p/9874985.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值