HDU 1073:Online Judge

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1073


题目意思:

输入T,T组测试数据。

每组数据提供两个文件,每个文件以START开始,以END结束。

然后如果两个文件完全相等,输出Accepted

否则两个文件除去空格,换行符和tab键外完全相同,输出Presentation Error

否则输出 Wrong Answer


注意:

如果输入空串,记得保留换行符,

其次就是串之间有空格,不要用scanf读入,用gets

题目写的我好崩溃,写的代码也不知道错哪了一直Wa,改了好久AC了。


AC代码:

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <queue>
#include <algorithm>

#define INF 0x3f3f3f3f
using namespace std;

char correct[50000];   ///正确的文件
char submit[50000];    ///提交的文件
char str[50000];       ///接收一个个字符串
char c[50000];         ///存放除去空格,制表符,换行等符号的正确文件
char s[50000];         ///存放除去空格,制表符,换行等符号的提交文件。
int main()
{
    int T;
    scanf("%d",&T);
    getchar();  ///注意吞掉换行
    while(T--)
    {
        strcpy(correct,"");     ///两个字符串初始化为空
        strcmp(submit,"");
        int len1 = 0;           ///第一个文件的长度
        while(gets(str))
        {
            int len = strlen(str);  
            if(len == 0)  ///空串,则放入换行
                correct[len1++] = '\n';
            else
            {
                for(int i = len1; i < len1+len; i++)
                {
                    correct[i] = str[i-len1];
                }
                len1 = len1 + len;
                correct[len1] = '\n';  ///保存换行符
                len1++;
            }
            if(strcmp(str,"END")==0)   ///是END结束
                break;
        }
        int len2 = 0;             ///提交文件的长度
        while(gets(str))
        {
            int len = strlen(str);
            if(len == 0)            ///空串加入换行即可
                submit[len2++] = '\n';
            else
            {
                for(int i = len2; i < len2+len; i++)
                {
                    submit[i] = str[i-len2];
                }
                len2 = len2 + len;
                submit[len2] = '\n';  ///保存换行符
                len2++;
            }
            if(strcmp(str,"END") == 0)
                break;
        }

        if(len1 == len2) ///长度相等
        {
            bool flag = true;
            for(int i = 0; i < len1; i++)
            {
                if(correct[i] != submit[i])
                {
                    flag = false;
                    break;
                }
            }
            if(flag)  ///两个字符串完全相等
                printf("Accepted\n");
            else      ///否则去掉换行、制表符和空格再次比较
            {
                int j = 0;
                for(int i = 0; i < len1; i++)
                {
                    if(correct[i]==' ' || correct[i]=='\t' || correct[i]=='\n')
                        continue;
                    else
                        c[j++] = correct[i];
                }
                c[j] = '\n';  ///末尾加换行符
                j = 0;
                for(int i = 0; i < len2; i++)
                {
                    if(submit[i]==' ' || submit[i]=='\t' || submit[i]=='\n')
                        continue;
                    else
                        s[j++] = submit[i];
                }
                s[j] = '\n';
                if(strcmp(s,c)==0)  
                    printf("Presentation Error\n");
                else
                    printf("Wrong Answer\n");
            }
        }
        else
        {
            int j = 0;
            for(int i = 0; i < len1; i++)
            {
                if(correct[i]==' ' || correct[i]=='\t' || correct[i]=='\n')
                    continue;
                else
                    c[j++] = correct[i];
            }
            c[j] = '\n';
            j = 0;
            for(int i = 0; i < len2; i++)
            {
                if(submit[i]==' ' || submit[i]=='\t' || submit[i]=='\n')
                    continue;
                else
                    s[j++] = submit[i];
            }
            s[j] = '\n';
            if(strcmp(s,c)==0)
                printf("Presentation Error\n");
            else
                printf("Wrong Answer\n");
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值