import java.util.*;
public class Main {
static int count=0;
static Map<String,String> map=new HashMap<String, String>();
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
ArrayList<String> list1=new ArrayList<String>();
ArrayList<String> list2=new ArrayList<String>();
Set<String> set=new HashSet<String>();
while(true){
String temp=scanner.nextLine();
if(!temp.equals("END")){
list1.add(temp);
}else{
break;
}
}
set.addAll(list1);
list1.clear();
list1.addAll(set);//数据去重
// System.out.println(list1);
while(true){
String temp=scanner.nextLine();
if(!temp.equals("END")){
list2.add(temp);
}else{
break;
}
}
//实现功能1排序
Collections.sort(list1,new SpecialSort());
for(String ss:list1){
System.out.println(ss);
}
System.out.println("END");
// System.out.println(list2);
Search(list1,list2);
for(int i=0;i<list2.size();i++){
System.out.println(list2.get(i)+" "+map.get(list2.get(i)+""));
}
}
public static void Search(ArrayList<String> list1,ArrayList<String> list2){
for(int i=0;i<list2.size();i++){
if(list1.contains(list2.get(i))){
map.put(list2.get(i)+"","found");
}else{
map.put(list2.get(i)+"","not Found");
}
}
}
}
class SpecialSort implements Comparator{
@Override
public int compare(Object o1, Object o2) {
int a=Integer.parseInt((String)o1);
int b=Integer.parseInt((String)o2);
if(a==b){
String so1=(String) o1;
String so2=(String) o2;
return so1.length()-so2.length();
}else{
return b-a;
}
}
}
3729:用set实现字符串的排序和查找
最新推荐文章于 2023-06-13 14:02:06 发布