原题:
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
KEY:这道题不是简单的两个数比较,是讨论的大数处理的问题,而且要考虑到带有小数点的大数的问题和小数点后的数字末尾有零和没有零是一样的问题
代码:
#include <iostream>
#include <string>
#include<stdio.h>
using namespace std;
void FINDDIAN(string &a)
{
int len = a.length();
if (a.find('.') != string::npos)
{
for (int i = len - 1; a[i] == '0'; i--) len--;
a = a.substr(0, len);
}
if (a[len - 1] == '.') a = a.substr(0, len - 1);
}
int main()
{
string A;
string B;
while (cin >> A >> B) {
FINDDIAN(A);
FINDDIAN(B);
if (A == B) cout << "YES" << endl;
if (A != B) cout << "NO" << endl;
}
return 0;
}
解题思路:
1.寻找有无小数点;
2.寻找小数点后的零是否多余;
3.去掉多余的零再进行比较;
写在最后:
做题时内心OS:
第一遍:这也太简单了吧(WA) 我:???
第二遍:哦~数太小了是吧,改成数组,strcmp!(WA) 我:?????
第三遍:难道数组也不行??那我用STRING总OK了吧 (WA) 我:???????
上网一查,原来如此,??