zoukankan      html  css  js  c++  java
  • [PAT] 1023 Have Fun with Numbers (20 分)Java

    Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!

    Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

    Input Specification:

    Each input contains one test case. Each case contains one positive integer with no more than 20 digits.

    Output Specification:

    For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.

    Sample Input:

    1234567899
    

    Sample Output:

    Yes
    2469135798


     1 import java.math.BigInteger;
     4 import java.util.ArrayList;
     5 import java.util.Collections;
     6 import java.util.Scanner;
     7 
     8 /**
     9  * @Auther: Xingzheng Wang
    10  * @Date: 2019/2/21 18:07
    11  * @Description: pattest
    12  * @Version: 1.0
    13  */
    14 public class PAT1023 {
    15     public static void main(String[] args) {
    16         Scanner sc = new Scanner(System.in);
    17         BigInteger number = sc.nextBigInteger();
    18         BigInteger result = number.multiply(new BigInteger("2"));
    19         ArrayList<Character> list1 = new ArrayList();
    20         ArrayList<Character> list2 = new ArrayList();
    21         sortOfNumber(list1,number);
    22         sortOfNumber(list2,result);
    23 
    24         if(list1.equals(list2))
    25             System.out.println("Yes");
    26         else
    27             System.out.println("No");
    28         System.out.println(result);
    29     }
    30     private static void sortOfNumber(ArrayList<Character> list,BigInteger number){
    31         String s = number.toString();
    32         char[] ch = s.toCharArray();
    33         for (char c : ch){
    34             list.add(c);
    35         }
    36         Collections.sort(list);
    37     }
    38 }
  • 相关阅读:
    Node.js meitulu图片批量下载爬虫1.04版
    Node.js meitulu图片批量下载爬虫1.03版
    Node.js meitulu图片批量下载爬虫1.02版
    Node.js 解析gzip网页(https)
    Node.js 访问https网站
    Node.js meitulu图片批量下载爬虫1.01版
    我曾经七次鄙视自己的灵魂 卡里.纪伯伦
    ZT:有些人,活了一辈子,其实不过是认真过了一天,其余时间都在重复这一天而已
    节点对象图与DOM树形图
    DOM(文档对象模型)基础加强
  • 原文地址:https://www.cnblogs.com/PureJava/p/10498039.html
Copyright © 2011-2022 走看看