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;
}


 
目录
相关文章
|
6月前
【每日一题Day242】LC1262可被三整除的最大和 | 贪心 dp
【每日一题Day242】LC1262可被三整除的最大和 | 贪心 dp
48 0
|
6月前
分解质因数答疑 为什么只需要枚举到根号N 为什么n % i == 0就是质数
分解质因数答疑 为什么只需要枚举到根号N 为什么n % i == 0就是质数
58 0
|
12月前
|
Java
hdu 1262 寻找素数对
hdu 1262 寻找素数对
34 0
|
机器学习/深度学习
[LeeCode][动态规划][简单] 杨辉三角
[LeeCode][动态规划][简单] 杨辉三角
54 0
P1216 [USACO1.5][IOI1994]数字三角形 Number Triangles
P1216 [USACO1.5][IOI1994]数字三角形 Number Triangles
POJ-2389,Bull Math(大数乘法)
POJ-2389,Bull Math(大数乘法)
HDOJ(HDU) 2521 反素数(因子个数~)
HDOJ(HDU) 2521 反素数(因子个数~)
107 0
HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)
HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)
99 0
|
Go
POJ 1503 Integer Inquiry 简单大数相加
POJ 1503 Integer Inquiry 简单大数相加
79 0