欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

(杭电 2054)A==B?(这真是个巨坑)

程序员文章站 2022-12-22 23:32:20
A == B ? Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 133531 Accepted Submission(s): 21293 Pro ......

a == b ?

time limit: 1000/1000 ms (java/others) memory limit: 32768/32768 k (java/others)total submission(s): 133531 accepted submission(s): 21293

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

这题真是一个巨坑

因为题中没有给出a,b是什么样的数,所以需要考虑的不仅仅是 大数 的问题还要考虑 小数 的问题。

我一开始没注意到小数点后还有数要去比就直接把小数点换成'\0'结果就wa了好几次(2333);

代表测试样例

0.0 0
yes
1.222 1
no

样例代码

#include <bits/stdc++.h>
using namespace std;

char a[100000],b[100000];
int main()
{
    while(~scanf("%s%s",a,b))
    {
        int oja=0,ojb=0;
        int lena=strlen(a);
        int lenb=strlen(b);
        for(int i=0; i <= lena-1; i++)
            if(a[i] == '.')
                oja=1;
        for(int i=0; i <= lenb-1; i++)
            if(b[i] == '.')
                ojb=1;
        if(oja == 1)        //下面的可以单独定义一个函数,不过tl不tl就不知道了
        {
            while(a[lena-1] == '0')
            {
                a[lena-1]='\0';
                lena--;
            }
            if(a[lena-1] == '.')
                a[lena-1] = '\0';
        }
        if(ojb == 1)
        {
            while(b[lenb-1] == '0')
            {
                b[lenb-1]='\0';
                lenb--;
            }
            if(b[lenb-1] == '.')
                b[lenb-1] = '\0';
        }
        if(strcmp(a,b) == 0)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}