hdu2054 A == B ?【大数】

简介: A == B ? Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 51920 Accepted Submission(s): 801...

A == B ?

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 51920 Accepted Submission(s): 8014


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
<pre name="code" class="java">import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner cin = new Scanner(System.in);
        while(cin.hasNext()){
            BigDecimal a = cin.nextBigDecimal();
            BigDecimal b = cin.nextBigDecimal();
            if(a.equals(BigDecimal.valueOf(0.0)))
                a = BigDecimal.ZERO;
            if(b.equals(BigDecimal.valueOf(0.0)))
                b = BigDecimal.ZERO;
            if(a.stripTrailingZeros().toPlainString().equals(b.stripTrailingZeros().toPlainString()))
                System.out.println("YES");
            else {
                System.out.println("NO");
            }
        }
        cin.close();
    }
}
#include<stdio.h>
#include<string.h>
char *removepoint(char a[])//不用考虑前导0...这让我很困惑啊..Dev结果都不对还能AC
{
	int len = strlen(a);
	//strchr的功能 : 
	//返回首次出现c的位置的指针,返回的地址是字符串在内存中
	//随机分配的地址再加上你所搜索的字符在字符串位置,如果s中不存在c则返回NULL 
	if(strchr(a,'.')!=NULL)
	{
		while(a[--len] == '0');
		if(a[len]=='.') len--;
		a[len+1] = '\0';
	}
	return a;
}
int main()
{
	char a[15000],b[15000];
	while(~scanf("%s%s",a,b))
	{
		if(strcmp(removepoint(a),removepoint(b))==0) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


 
目录
相关文章
|
机器学习/深度学习
[LeeCode][动态规划][简单] 杨辉三角
[LeeCode][动态规划][简单] 杨辉三角
50 0
POJ-2389,Bull Math(大数乘法)
POJ-2389,Bull Math(大数乘法)
HDOJ(HDU) 2504 又见GCD(利用最大公约数反推)
HDOJ(HDU) 2504 又见GCD(利用最大公约数反推)
98 0
HDOJ/HDU 2561 第二小整数(水题~排序~)
HDOJ/HDU 2561 第二小整数(水题~排序~)
107 0
HDOJ(HDU) 2521 反素数(因子个数~)
HDOJ(HDU) 2521 反素数(因子个数~)
105 0
|
Go
POJ 1503 Integer Inquiry 简单大数相加
POJ 1503 Integer Inquiry 简单大数相加
76 0
|
测试技术
HDOJ(HDU) 1859 最小长方形(水题、、)
HDOJ(HDU) 1859 最小长方形(水题、、)
74 0