HDU 2054 A == B ?

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2054

题意:给两个高精度大数,判断是否相等。

解法:

大数:采用数组储存各位数字。
小数点(高精度数字):先消除小数点以及末尾的0,再用strcmp对字符串进行比较。

AC:

#include <bits/stdc++.h>
using namespace std;
bool point(char *p)
{
    int l = strlen(p);
    for(int i = 0 ; i < l ; i++)
        if(p[i]=='.') return true;
    return false;
}
void change(char *p)
{
    int l = strlen(p);
    if(point(p))
    {
        for(int i = l-1 ; p[i]=='0' ; i--)
        {
            p[i] = '';
            l--;
        }
        if(p[l-1]=='.') p[l-1] = '';
    }
}
int main()
{
    char a[100005] ,b[100005];
    while(cin >> a >> b)
    {
        change(a);
        change(b);
        if(strcmp(a,b)==0) cout << "YES" <<endl;
        else cout << "NO" <<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zz990728/p/8886276.html