HDU - 2054 A == B ?

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

 【注】:这个题的关键是“找小数点”,把小数部分末尾的0去掉,再进行比较。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

char a[20000], b[20000];

void change(char s[])
{
    int len = strlen(s);
    if (strchr(s, '.') != NULL)
    {
        while (s[--len] == '0')
            ;
        if (s[len] == '.')
            len--;
        s[len+1] = '\0';
    }
}

int main()
{
    while (scanf("%s %s", a, b) != EOF)
    {
        change(a);
        change(b);
        if (strcmp(a, b) == 0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
发布了329 篇原创文章 · 获赞 342 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/Aibiabcheng/article/details/105336845