HDOJ 2054 A == B ?

本文详细介绍了如何通过简单的代码逻辑判断两个数值变量是否相等,包括输入处理、字符串操作及特殊情况处理。通过实例演示了算法实现过程,包括错误处理和优化建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
 
Input
each test case contains two numbers A and B.
 
Output
for each case, if A is equal to B, you should print "YES", or print "NO".
 
Sample Input
  
1 2 2 2 3 3 4 3
 
Sample Output
  
NO YES YES NO
已AC:
#include <iostream>
#include <string>
void Erase(std::string & s);

int main()
{
    using namespace std;
    string a, b;
    while(cin >> a >> b)    //易考虑不周全
    {
        int k = 0;
        Erase(a);
        Erase(b);
        if(a==b)
            cout << "YES";
        else
            cout << "NO";
        cout << endl;
    }
    return 0;
}

void Erase(std::string & s)
{
    if(s.find('.')!=std::string::npos)  //查找单字符成员函数!!
    {
        int k = s.size()-1;
        while(s[k]=='0')
        {
            k--;
            s.erase(k+1, 1);        //活用string类!
        }
        if(s[k]=='.')
        {
            k--;
            s.erase(k+1, 1);
        }
    }

}

略有难度,AC率只有 15.31%( 7449 / 48655 )。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值