现在的位置: 首页 > 综合 > 正文

HDOJ 2054 A == B ?

2018年11月08日 ⁄ 综合 ⁄ 共 647字 ⁄ 字号 评论关闭
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)。

抱歉!评论已关闭.