首页 > 其他 > 详细

PAT1005

时间:2018-03-24 12:38:36      阅读:191      评论:0      收藏:0      [点我收藏+]

代码如下:

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        int num = input.nextInt();
        ArrayList<Integer> arrList = new ArrayList<Integer>();
        for(int i = 0;i<num;i++){
            arrList.add(input.nextInt());
        }
        ArrayList<Integer> arrListTemp = new ArrayList<Integer>(arrList);
        for(int j = 0;j<num;j++){
            int temp = arrListTemp.get(j);
            while(temp!=1){
                if(temp%2==1){
                    temp = (temp*3+1)>>1;
                    if(arrList.contains(temp)){
                        arrList.remove(Integer.valueOf(temp));
                    }
                }else{
                    temp = temp>>1;
                    if(arrList.contains(temp)){
                        arrList.remove(Integer.valueOf(temp));
                    }
                }
            }
        }
        Collections.sort(arrList,Collections.reverseOrder());
        for(int k = 0;k<arrList.size();k++){
            if(k==(arrList.size()-1)){
                System.out.print(arrList.get(k));
            }else{
                System.out.print(arrList.get(k)+" ");
            }
        }
    }
}

 

PAT1005

原文:https://www.cnblogs.com/LoganChen/p/8638345.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!