AcWing 1500. 趣味数字(Java)
原题链接
简单
作者:
码海泛舟
,
2020-07-17 10:01:00
,
所有人可见
,
阅读 589
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
//可能是20位,需要高精度
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String A = sc.next();
ArrayList<Integer> a = new ArrayList<>();
for (int i = A.length() - 1; i >= 0; i--) {//低位在前,存储A
a.add(A.charAt(i) - '0');
}
//翻倍之后存到b
ArrayList<Integer> b = new ArrayList<>();
int t = 0;
for (int i = 0; i < a.size(); i++) {
int s = a.get(i) * 2 + t;
b.add(s % 10);
t = s / 10;
}
if (t > 0) b.add(1);
//比较是否只是数字顺序不同
ArrayList<Integer> c = (ArrayList<Integer>) b.clone();
Collections.sort(a);
Collections.sort(c);
if (a.equals(c)) {
System.out.println("Yes");
} else {
System.out.println("No");
}
for (int i = b.size() - 1; i >= 0; i--) {
System.out.print(b.get(i));
}
}
}