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-09-23 12:28:49

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

hdu 1073 Online Judge

    非常简单的字符串匹配,懒得又读取又切割,于是就用了一个懒一点的方法直接比较了 /* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring

HDOJ/HDU 1088 Write a simple HTML Browser(HTML字符串)

Problem Description If you ever tried to read a html document on a Macintosh, you know how hard it is if no Netscape is installed. Now, who can forget to install a HTML browser? This is very easy because most of the times you don't need one on a MAC

HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)

Problem Description Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book

HDOJ/HDU 1200 To and Fro(加密解密字符串)

Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write the message (letters only) down the columns, padding with extra random letters so as to make a rectangular array

HDOJ/HDU 1982 Kaitou Kid - The Phantom Thief (1)(字符串处理)

Problem Description Do you know Kaitou Kid? In the legend, Kaitou Kid is a master of disguise, and can take on the voice and form of anyone. He is not an evil person, but he is on the wrong side of the law. He's the very elusive phantom thief who nev

HDOJ(HDU) 2500 做一个正气的杭电人(水~)

Problem Description 做人要有一身正气,杭电学子都应该如此.比如我们今天的考试就应该做到"诚信"为上. 每次考试的第一个题目总是很简单,今天也不例外,本题是要求输出指定大小的"HDU"字符串,特别地,为了体现"正气"二字,我们要求输出的字符串也是正方形的(行数和列数相等). Input 输入的第一行包含一个正整数N(N<=20),表示一共有N组数据,接着是N行数据,每行包含一个正整数M(M<=50),表示一行内有M个

HDOJ/HDU 1161 Eddy&amp;#39;s mistakes(大写字母转换成小写字母)

Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy's English teacher be extremely disco

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)

Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game can be played by two or more t

HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)

Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input 输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是老师交给Ignatius统计的单词,一个空行代表单词表的结束.第二部分是一连串的提问,每行一个提问,每个提问都是一个字符串. 注意:本题只有一组测试数据,处理到文件结束. Output 对于每个提