hdu - 2054 - A == B ?

题意:输入两个数字A, B,如果A等于B,输出“YES”,否则输出“NO”。

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

——>>开始以为,好简单呀,直接输入两个string,然后用==判断,一次WA,改用直接输入两个double,然后用==判断,再次WA……原来,这不是那么好过的题!要考虑前导0与有小数点的尾0。不过貌似不用考虑负数的情况,因为我的程序过不了0, -0还有-12, -012这样的数据,但可以AC! (最后一次WA,是因为开了10000+10的大小,还差一个0,这题目……)

#include <cstdio>
#include <cstring>

using namespace std;

const int maxn = 100000 + 10;

char A[maxn], B[maxn];

void simplify(char *s)
{
    while(*s == '0') s++;
    if(strchr(s, '.'))
    {
        int len = strlen(s);
        char *p = s + len - 1;
        while(*p == '0') *(p--) = 0;
        if(*p == '.') *p = 0;
    }
}
int main()
{
    while(~scanf("%s%s", A, B))
    {
        simplify(A);
        simplify(B);
        if(strcmp(A, B) == 0) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值