hdu 1073 字符串处理 c++版 附一组易错数据

1
START
You are wrong!
END
START
You a
re wrong!
END

应输出  Presentation Error

 

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
void delspace(string &s)     //删除字符串中的空格(' ') tab('\t')
{
    int a;
    while(1)
    {
        a=s.find_first_of(" \t");   //返回字符串中第一个与" \t"中字符匹配的位置
        if(a==-1)return;             //如果没有匹配的,此函数返回-1
        s.erase(s.begin()+a,s.begin()+a+1);//迭代器删除法
    }
}
int main()
{

      //freopen("in.txt","r",stdin);   //用于文件输入 方便测试数据
      string s1,s2,garbage;
      string str1,str2;
      int acount;
      scanf("%d",&acount);
      while(acount--)
      {
          int line1=0,line2=0;
          cin>>garbage;//start
          str1="";
          str2="";
          while(1)
          {
              getline(cin,s1);//此函数能得到空格 得不到\n
              str1+=s1;     //注意这样加起来就没有 \n了
              if(s1=="END")break;
              line1++;       //我们维护一个line1变量,看看有多少行
          }
          cin>>garbage;//start
          while(1)
          {
              getline(cin,s2);
              str2+=s2;
              if(s2=="END")break;
              line2++;
          }
          if(str1==str2&&line1==line2) //注意是两个条件哦 用最上面的数据测试下就知道为什么了
          {
              printf("Accepted\n");
              continue;
          }
          delspace(str1);
          delspace(str2);
          if(str1==str2)
          {
              printf("Presentation Error\n");
              continue;
          }
          printf("Wrong Answer\n");
      }

    return 0;
}
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会写代码的孙悟空

赠人玫瑰 手有余香

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值