HDOJ/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

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

就是输入输出,简单的判断PE,WA,AC这几种情况。

START是开始输入了,

END是结束输入了。数据在这个之间!

每一组有2个 START和END。

就是判断这2个之间的数据是PE,WA还是AC。

分析:

用2字符串分别存储这2个需要比较的数据,遇到换行需要在字符串中加入’\n’。

先看这2个字符串是不是相等,如果相等,就是AC。

不相等,再来判断是PE还是WA。

import java.util.Scanner;
/**
 * @author 陈浩翔
 *
 * 2016-5-26
 */
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        sc.nextLine();
        while (t-- > 0) {
            String a = "";
            String b = "";
            while (true) {
                String str = sc.nextLine();
                if ("END".equals(str)) {
                    break;
                }
                if ("START".equals(str)) {
                    continue;
                }
                a=a+str;
                a=a+"\n";
            }

            while (true) {
                String str = sc.nextLine();
                if ("END".equals(str)) {
                    break;
                }
                if ("START".equals(str)) {
                    continue;
                }
                b=b+str;
                b=b+"\n";
            }
            int con = 0;// -1--PE,0--WA,1--AC

//          System.out.println(a);
//          System.out.println(a.length());
//          System.out.println(b);
//          System.out.println(b.length());

            if(a.equals(b)){
                con=1;
            }else{
                con=-1;
                String stra="";
                for(int i=0;i<a.length();i++){
                    if(a.charAt(i)==‘ ‘||a.charAt(i)==‘\t‘||a.charAt(i)==‘\n‘){
                        continue;
                    }
                    stra=stra+a.charAt(i);
                }
                String strb="";
                for(int i=0;i<b.length();i++){
                    if(b.charAt(i)==‘ ‘||b.charAt(i)==‘\t‘||b.charAt(i)==‘\n‘){
                        continue;
                    }
                    strb=strb+b.charAt(i);
                }
//              System.out.println(stra);
//              System.out.println("-------------");
//              System.out.println(strb);
                if(stra.equals(strb)){
                    con=-1;
                }else{
                    con=0;
                }
            }

            if(con==0){
                System.out.println("Wrong Answer");
            }else if(con==-1){
                System.out.println("Presentation Error");
            }else{
                System.out.println("Accepted");
            }
        }
    }
}
时间: 2024-12-14 18:05:50

HDOJ/HDU 1073 Online Judge(字符串处理~)的相关文章

HDU ACM 1073 Online Judge -&gt;字符串水题

分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read(char p[]) { getchar(); gets(tmp); while(gets(tmp)) { if(strcmp(tmp,"END")==0) break; if(strlen(tmp)!=0) strcat(p,tmp); strcat(p,"\n");

解题报告:hdu 1073 Online Judge

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1073 题目是英文,在这里用中文显示: 伊格内修斯正在建立一个在线法官,现在他已经研究出除法官系统以外的所有问题.系统必须从正确的输出文件和用户的结果文件读取数据,然后系统比较这两个文件.如果两个文件绝对相同,则判定系统返回"Accepted",否则如果两个文件之间的唯一区别是空格('  '),制表符('\t')或输入('\n'),法官系统应返回"Presentation Erro

HDOJ/HDU 1062 Text Reverse(字符串翻转~)

Problem Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input contains several test cases. The first line of the inpu

HDU 1073 Online Judge

字符串比较,3种结果:AC,PE,WA:为了好处理中间的数据让所有输入的字符串连起来并且让两种输入的行数相同,(除却空行) 一个输入函数,一个处理函数 附代码 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int N=5005; 6 void input(char s[]) { 7 s[0]='\0'; 8 char tmp[N]

HDOJ/HDU 2140 Michael Scofield&#39;s letter(字符转换~)

Problem Description I believe many people are the fans of prison break. How clever Michael is!! In order that the message won't be found by FBI easily, he usually send code letters to Sara by a paper crane. Hence, the paper crane is Michael in the he

hdoj 2072 单词数 【字符串处理】

题目大意: 输入一组字符串,只由小写字母和空格组成,让你统计不同单词的个数,注意是不同的个数 . 特殊数据 1,直接输入一个换行,应该输出0 2,连续输出多个空格 在加上一个换行 应该输出0 3,输入 "ni shi wo wo de de de de hao     hao "应该输出5 6, 输入" 空格空格ni空格空格shi     " 应该输出2 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2072 #in

魔咒词典------HDOJ杭电1880(字符串的处理,很简单)

Problem Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助. 给你一部魔咒词典.当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能:当哈利需要某个功能但不知道该用什么魔咒时,你的程序要替他找到相应的魔咒.如果他要的魔咒不在词典中,就输出"what?" Input 首先列出词典中不超过100000条不同的魔咒词条,每条格式

HDU 2072 单词数 --- 字符串处理

/* HDU 2072 单词数 --- 字符串处理 */ #include <cstdio> //C语言改成stdio.h即可 #include <cstring> //C语言改成string.h即可 const int maxn = 85; int main() { char *head1, *head2; char a[maxn]; char b[maxn][maxn]; int i, k, len, cnt1, cnt2; while (gets(a)){ //遇到字符串&q

UVa 489 Hangman Judge(字符串)

 Hangman Judge  In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follo