题意:判断两个大数是否相等。
注意:1. == 1 ;1.这个输入不是非法输入;只要把没有用的0去掉就OK了。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String a = sc.next();
String b = sc.next();
a = sweepZeroAndBlock(a);
b = sweepZeroAndBlock(b);
if (a.equals(b)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
// 去掉s字符串中无用的0和空白
private static String sweepZeroAndBlock(String s) {
int i = s.indexOf(".");
StringBuffer temp = new StringBuffer();// 不用这个会超内存
if (i > 0) {// 是小数
int len = i - 1;// 如果小数点后没有值那么小数点也不要
for (int j = s.length() - 1; j > i; j--) {
char ch = s.charAt(j);
if (ch >= '1' && ch <= '9') {
len = j;
break;
}
}
// 把字符串s中有用的数据拷贝到temp中
for (int j = 0; j <= len; j++) {
temp.append(s.charAt(j));
}
s = temp.toString();
}
return s;
}
}
A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 73637 Accepted Submission(s): 11627
Problem Description
Give you two numbers A and B, if A is equal to B, you should print , or print "NO".
给你两个数字A和B,如果A=B,你应该输出"YES",否着输出"NO"。(A和B是大数,一般的数据类型都装不下)
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".
对于每一个测试事件,你应该输出YES",否着输出"NO"。
Sample Input
1 2 2 2 3 3 4 3
Sample Output
NO YES YES NO
Author
8600 && xhd
Source