A==B?

题目链接如下

https://vjudge.net/contest/235898#problem/Y

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

这道题初看以为十分简单但是,只是说A,B是数,没说数据类型,考虑用字符串,用strcmp函数比较A,B输

但是这存在一个问题 19.10000 和19用strcmp函数比较,结果是NO

那改变吧,去掉0

代码如下(有bug)

while(a[i]=='0'&&i>=0)i--;
if(a[i]=='.')a[i]='\0';
else a[i+1]='\0';

但是这又存在一个问题110.0000 和110也是No当时因为这个bug卡了很久

后来修改为

#include<cstdio>
#include<cstring>
char str1[100000],str2[100000];
void dezero(char a[])
{
	int i=strlen(a)-1;
	if(strchr(a,'.'))
	{
	while(a[i]=='0'&&i>=0)i--;
	if(a[i]=='.')a[i]='\0';
	else a[i+1]='\0';
	}
 }
 int main()
 {
	while(scanf("%s%s",str1,str2)!=EOF)
	{
		dezero(str1),dezero(str2);
		if(!strcmp(str1,str2))printf("YES\n");
		else printf("NO\n");
	}
	return 0;
 }

猜你喜欢

转载自blog.csdn.net/qq_41626975/article/details/81350144