6-14 Duplicated Numbers (10分)

This program reads a lot of integers, in which may be duplicated numbers. The program picks out all the duplicated ones and sorts the remainders in a descendent order.

函数接口定义:

public static ArrayList<Integer> pick(ArrayList<Integer> a);

a is the ArrayList to be parsed and returns the result as an ArrayList.

裁判测试程序样例:

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;public class Main {/* 请在这里填写答案 */public static void main(String[] args) {ArrayList<Integer> lst = new ArrayList<>();Scanner in = new Scanner(System.in);while ( in.hasNextInt() ) {lst.add(in.nextInt());}lst = pick(lst);for ( int x:lst) {System.out.print(x+" ");}System.out.println();in.close();}
}

输入样例:

1 1 2 3 4 5 9 3

输出样例:

9 5 4 3 2 1 

public static ArrayList<Integer> pick(ArrayList<Integer> a)    {
        ArrayList<Integer> rs = new ArrayList<Integer>();
        for(int i=0;i<a.size();i++) {    
            if(!rs.contains(a.get(i))) {
                rs.add(a.get(i));
            }
        }
        Collections.sort(rs);
        Collections.reverse(rs);
        return rs;
    }

Duplicated Numbers (10分)相关推荐

  1. 7-24 First 50 Prime Numbers (10 分)

    7-24 First 50 Prime Numbers Your program reads one natural numbers n in, and prints out the sum of t ...

  2. 【PAT (Advanced Level) Practice】1120 Friend Numbers (20 分)

    1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same ...

  3. PAT_(STL使用)map-1100 Mars Numbers (20分)-1054 The Dominant Color (20分)-1071-1022

    目录 1100 Mars Numbers (20分) 1054 The Dominant Color (20分) 1071 Speech Patterns (25分) 1022 Digital Lib ...

  4. 考研国家线罕见大幅上涨,12个学科涨幅10分以上,超300万人将落榜

    金磊 博雯 发自 凹非寺 量子位 | 公众号 QbitAI 随着2022年研考国家线的发布,"考研"这一话题再次成为焦点. 据央视网报道,全国457万考研大军,院校计划招生人数约1 ...

  5. 7-5 密码锁 (10 分)

    7-5 密码锁 (10 分) 在神秘的乌啦啦国度有一个非常神秘的基地,多年来,小明家族一直在为前往神秘基地而努力着.终于在历经数千年的探索之后,他们来到了神秘基地的大门口. 现在他们站在入口处,但要进 ...

  6. C语言函数题-取子串 (10分)

    6-3取子串 (10分) 编写代码,完成从指定字符串中取指定子串的代码(不利用string.h类库),给定的是子串起始位置和长度,返回一个新的子字符串的首地址.如果起始位置不妥,返回空串.如果后面的子 ...

  7. C语言入门题-7-1 最大和最小 (10分)

    7-1 最大和最小 (10分) 请使用指针法(间接访问)编写程序,程序的功能是从键盘输入 10 个数,求其最大值和最小值的差. 输入格式: 输入10个整数 输出格式: 无 输入样例: 1 2 3 4 ...

  8. C语言程序练习- L1-040 最佳情侣身高差 (10分)

    L1-040 最佳情侣身高差 (10分) 专家通过多组情侣研究数据发现,最佳的情侣身高差遵循着一个公式:(女方的身高)×1.09 =(男方的身高).如果符合,你俩的身高差不管是牵手.拥抱.接吻,都是最 ...

  9. C语言程序练习-L1-018 大笨钟 (10分)

    L1-018 大笨钟 (10分) 微博上有个自称"大笨钟V"的家伙,每天敲钟催促码农们爱惜身体早点睡觉.不过由于笨钟自己作息也不是很规律,所以敲钟并不定时.一般敲钟的点数是根据敲钟 ...

最新文章

  1. ios 界面间跳转方法总结
  2. Android复习04(适配器 Get()请求 适配器 getView()方法 Post()请求 保存Cookie 流转字符串 从网上获取图片 重点考Json解析)
  3. 程序员必知的8大排序(三)-------冒泡排序,快速排序(java实现) .
  4. 【BZOJ3028】食物(生成函数)
  5. zynq linux opencv效率,2 - 基于ZYNQ7000的交叉编译工具链Qt+OpenCV+ffmpeg等库支持总结
  6. Linux系统学习:目录结构和文件管理指令
  7. CF620E New Year Tree
  8. 大数据工程师简历_大数据毕业生简历该怎么写?
  9. lol更新显示正在连接服务器,wegame更新游戏显示正在连接服务器
  10. 视频会议系统管理规章制度
  11. Unicast与Multicast
  12. 微信支付 django
  13. UEFI 中的Gmac网卡驱动实现
  14. 微软surface屏幕测试软件,【微软 Surface Pro 3 平板电脑使用感受】屏幕|软件_摘要频道_什么值得买...
  15. 计算机与网络应用封面,计算机二级考试真题-Word-小王-计算机与网络应用
  16. python时间戳转日期格式(保留毫秒级别)
  17. 12. 自制操作系统: risc-v ACLINT
  18. nginx鉴权之后查看pdf报错未能加载pdf文档
  19. 用Project软件编制项目计划【总结】
  20. Smarty Uninstaller v4.10.0 智能卸载工具,可以用来卸载Matlab 2019b

热门文章

  1. springboot 优雅关闭_Springboot 优雅停止服务的几种方法
  2. Java基础---方法1
  3. Java分布式唯一ID生成方案——比UUID效率更高的生成id工具类
  4. phantomjs搭建输出js渲染后的html接口
  5. mpvue使用vant Weapp运行npm run build命令打包后失效
  6. BZOJ 1192 [HNOI2006]鬼谷子的钱袋 (思维)
  7. VM虚拟机连Linux黑屏问题
  8. 16.1117 NOIP 模拟赛
  9. float,absolute脱离文档流的总结
  10. WebView点击图片看大图效果