zoukankan      html  css  js  c++  java
  • HDU-1703 Online Judge (练习处理输入)

    一、题目概述

     
    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

     

    二、题目释义

    获取输入,比对两个字符串,根据结果输出不同的答案

    三、思路分析

    这道题关键在于怎么处理输入,这里就需要许多对输入、字符、字符串的处理,一个一个读字符可以读取所有(回车符什么的都可以),但这样做这道题效率会偏低,这里我们用cin.getline()来读取整行,用strcmp()来做读取时转存的比较,用strcat()保存完成的字符串拼接,以正确获取两个answer。之后再做判断处理,判断相对读取是比较简单的。

    四、AC代码

    代码借鉴自其他博主

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <cstring>
    using namespace std;
    
    const int N = 5050;
    void input(char a[]);
    void simplify(char a[]);
    int cmp(char a[],char b[]);
    char s1[N]={0},s2[N]={0};
    
    int main(){
        int n;
        scanf("%d",&n);
        while(n--)
        {
            memset(s1,0,sizeof(s1));
            memset(s2,0,sizeof(s2));
            input(s1),input(s2);
            int m = cmp(s1,s2);
            switch(m)
            {
            case 1:
                printf("Accepted
    ");break;
            case 2:
                printf("Presentation Error
    ");break;
            case 3:
                printf("Wrong Answer
    ");break;
            }
        }
        return 0;
    }
    void input(char a[])
    {
        char s[N];
        while(scanf("%s",s),strcmp(s,"START"));
        while(cin.getline(s,N),strcmp(s,"END"))
        {
            if(s[0] != '')
                strcat(a,s);
            else strcat(a,"
    ");
        }
    }
    
    void simplify(char a[])
    {
        int i,k=0;
        char s[N];
        for(i=0; a[i]!=''; i++)
        {
            if(a[i]==' '||a[i]=='
    '||a[i]=='	')
                continue;
            s[k++]=a[i];
        }
        s[k++]='';
        strcpy(a,s);
    }
    
    int cmp(char a[],char b[])
    {
        if(!strcmp(a,b))
            return 1;
        simplify(a),simplify(b);
        if(!strcmp(a,b))
            return 2;
        return 3;
    }
  • 相关阅读:
    RDIFramework.NET ━ .NET快速信息化系统开发框架钜献 V2.9 版本震撼发布
    免费的海量编程中文书籍索引-都是干货【强烈建议收藏】
    SQLServer2005+附加数据库时出错提示操作系统错误5(拒绝访问)错误5120的解决办法
    实例演示使用RDIFramework.NET 框架的工作流组件进行业务流程的定义—请假申请流程-Web
    RDIFramework.NET 框架之组织机构权限设置
    实例演示使用RDIFramework.NET 框架的工作流组件进行业务流程的定义—请假申请流程-WinForm
    RDIFramework.NET ━ 9.16 案例模块━ Web部分
    RDIFramework.NET ━ 9.15 个性化设置 ━ Web部分
    RDIFramework.NET ━ 9.14 数据库连接管理 ━ Web部分
    RDIFramework.NET ━ 9.13 系统日志与系统异常管理 ━ Web部分
  • 原文地址:https://www.cnblogs.com/EcliWalker/p/8329159.html
Copyright © 2011-2022 走看看