概述
java旧题复习
6-1 Duplicated Words (20分)
This program reads a lot of words, in which may be duplicated words. The program picks out all the duplicated ones and sorts the remainders in a descendent order.
函数接口定义:
public static ArrayList pick(ArrayList 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<String> lst = new ArrayList<>();
Scanner in = new Scanner(System.in);
while ( in.hasNext() ) {
lst.add(in.next());
}
lst = pick(lst);
for ( String x:lst) {
System.out.print(x+" ");
}
System.out.println();
in.close();
}
}
输入样例:
this is a test at this Zhejiang University
输出样例:
this test is at a Zhejiang University
ans:
public static ArrayList<String> pick(ArrayList<String> a){
ArrayList<String> list=new ArrayList<>();
for(int i=0;i<a.size();i++) {
if(list.contains(a.get(i))==false) {
list.add(a.get(i));
}
}
Collections.sort(list);
Collections.reverse(list);
return list;
}
最后
以上就是故意小猫咪为你收集整理的6-1 Duplicated Words (20分)的全部内容,希望文章能够帮你解决6-1 Duplicated Words (20分)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复