#2054:A == B ?(水題坑人)

Problem Descriptionc++

Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".測試

Inputspa

each test case contains two numbers A and B.code

Outputip

for each case, if A is equal to B, you should print "YES", or print "NO".ci

Sample Inputstring

1 2
2 2
3 3
4 3

Sample Outputit

NO
YES
YES
NO

思路:io

此題關鍵是找小數點,找到小數點把最後面無效的零去掉再比較就OKclass

教訓:

一開始作的時候感受好簡單啊,直接string輸入而後==比較,而後WA打臉了,發覺多是大數比較問題,而後long double測試仍是沒過,想了好久纔想到多是精度問題如000123 和 123 還有小數點 ' . '的問題一些的,不斷完善最後才AC了

AC代碼

#include<bits/stdc++.h>
using namespace std;
void trim0(string& b)
{
	int len = b.length();
	if(b.find('.')!=string::npos)
	{
		for(int i=len-1;b[i]=='0';i--)
			len--;
		b=b.substr(0,len);
	}
	if(b[len-1]=='.')
		b=b.substr(0,len-1);
}
void main()
{
	string a,b;
	while(cin>>a>>b)
	{
		trim0(a);
		trim0(b);
		if(a==b)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
}
相關文章
相關標籤/搜索