zoukankan      html  css  js  c++  java
  • HDU 1073 Online Judge(字符串)

    Online Judge

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 4977    Accepted Submission(s): 1889


    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(' '), or enters(' '), 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
     

    题意:代码在线评測。返回三种结果,ac,pe,wa。 非常水的字符串处理,1A。


    #include <cstdlib>
    #include <string>
    #include <iostream>
    #include <sstream>
    #include <cctype>
    
    using namespace std;
    
    string src, dest, start, end;
    char sa[5001], sb[5001];
    
    void readContent(string &s){
    	s.clear();
    	string ts;
    	while (getline(cin, ts)){
    		if (ts != "END"){
    			s += ts;
    			s += "
    ";
    		}
    		else{
    			break;
    		}
    	}
    }
    
    void judge(const string &src, const string &dest, bool &af, bool &pf, bool &wf){
    	af = pf = wf = false;
    	if (src == dest){
    		af = true;
    		return;
    	}
    	pf = true;
    
    	int pos = 0;
    	for (int i = 0; i < src.length(); ++i){
    		if (!isspace(src[i])){
    			sa[pos++] = src[i];
    		}
    	}
    	sa[pos] = 0;
    
    	pos = 0;
    	for (int i = 0; i < dest.length(); ++i){
    		if (!isspace(dest[i])){
    			sb[pos++] = dest[i];
    		}
    	}
    	sb[pos] = 0;
    
    	if (strcmp(sa, sb) != 0){
    		wf = true;
    	}
    }
    
    int main(){
    	int t;
    	bool af, pf, wf;
    
    	cin >> t;
    
    	while (t--){
    		cin >> start;
    		readContent(src);
    		cin >> start;
    		readContent(dest);
    		judge(src, dest, af, pf, wf);
    
    		if (af){
    			cout << "Accepted" << endl;
    		}
    		else if (wf){
    			cout << "Wrong Answer" << endl;
    		}
    		else{
    			cout << "Presentation Error" << endl;
    		}
    	}
    	return 0;
    }



  • 相关阅读:
    经济地理国情监测
    《城市轨道交通——产业关联理论与应用》读书笔记
    《区域经济学原理》读书笔记(上)
    《国家经济地理》杂志之第一期:探寻中国经济的“第四极”
    《地理空间分析——原理、技术与软件工具》读书笔记
    《国家经济地理》杂志第二期:再望万里海疆——走向海洋经济的中国“大航海时代”
    国家统计遥感项目、商业图盟与品牌地图的碎碎念
    关于城市规划中的投融资规划
    区域功能定位对北京人口总量及分布的影响
    《中国经济地理——经济体成因与地缘架构》读书笔记
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/8350041.html
Copyright © 2011-2022 走看看