HDU 2054 A == B ?

2014-11-23 21:54:13 · 作者: · 浏览: 11

A == B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 49760 Accepted Submission(s): 7654


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

总结:

题目和简单,但是要考虑和多情况:

1. 全部为0的情况

2.有正负号的情况

3.浮点数(删掉小数点前面的0和小数点后面的0)

例子:

1: +00.0和-0 、+0和-0 、00.00 和0 等等全部为0 的情况;
2: 001.1和1.10 、000.01 和0.010 、+000.01 和-0.010 等等

3: 01.10 和01.1 、+01.10 和-01.1等等

4: 001.1 和1.1、-001.1 和+1.1 等等

import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(new BufferedInputStream(System.in));
		while(sc.hasNext()){
			String s1=sc.next();
			String s2=sc.next();
			s1=fun(s1);
			s2=fun(s2);
			if(s1.equals(s2))
				System.out.println("YES");
			else System.out.println("NO");
		}
	}
	public static String fun(String s){
		boolean b=true;
		//处理全部为0的情况
		for(int i=0;i