A == B ? HOJ2054 (字符串(小数点))

来源:互联网 发布:云计算有什么意义 编辑:程序博客网 时间:2024/06/06 10:56

A == B ?

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 153 Accepted Submission(s): 68 
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 22 23 34 3
 
Sample Output
NOYESYESNO
 

。。。这个题不存在前导零(哇。 考虑 1.          1          1.000 这些特殊情况。
本弱直接用的 std::string
#include <iostream>#include <cmath>#include <string>#include <algorithm>#include <string.h>using namespace std;int main() {    string a, b;    while (cin >> a >> b) {        if (a.find('.') < a.size()) {            while (a.end() != a.begin()) {                if (*(a.end() - 1) == '0') {                    a.erase(a.end() - 1);                } else                    break;            }                        if(*(a.end()-1) == '.')                a.erase(a.end() - 1);        }        if (b.find('.') < b.size()) {            while (b.end() != b.begin()) {                if (*(b.end() - 1) == '0') {                    b.erase(b.end() - 1);                } else                    break;            }            if(*(b.end()-1) == '.')                b.erase(b.end() - 1);        }            //cout << "|" << a << "|   |" << b <<"|"<< endl;        if (a == b)            cout << "YES" << endl;        else            cout << "NO" << endl;    }    }


原创粉丝点击