• 双向排序比较


    package clean;

    import java.util.ArrayList;
    import java.util.List;


    public class Test_ {

    public static void main(String[] args) {

    //8,10,12
    //8,10,12,13,15,18
    //8,10
    //8,12,13,18
    List<Integer> idList1 = new ArrayList<Integer>();
    idList1.add(8);
    // idList1.add(10);
    idList1.add(12);
    idList1.add(13);
    idList1.add(18);

    //8,10,12,13,15,18
    //8,10,12
    //8,12,13,18
    //8,10
    List<Integer> idList2 = new ArrayList<Integer>();
    idList2.add(8);
    idList2.add(10);
    // idList2.add(12);
    // idList2.add(13);
    // idList2.add(15);
    // idList2.add(18);


    compare(idList1, idList2);
    }


    public static void compare(List<Integer> idList1,List<Integer> idList2){
    int matchCount = 0;
    int notmatchCount_list1 = 0;
    int notmatchCount_list2 = 0;

    long id_list1 = 0;
    long id_list2 = 0;
    int j = 0;
    for(int i = 0; i < idList1.size();i++){
    id_list1 = idList1.get(i);

    if(j == idList2.size()){
    notmatchCount_list1++;
    continue;
    }


    for(; j < idList2.size();j++){
    id_list2 = idList2.get(j);
    if(id_list1 == id_list2){
    matchCount++;

    j++;
    if(i == idList1.size() - 1){
    for(; j < idList2.size();j++){
    notmatchCount_list2++;
    }
    }
    break;
    }else if(id_list1 < id_list2){
    notmatchCount_list1++;
    if(i == idList1.size() - 1){
    notmatchCount_list2++;
    j++;
    for(; j < idList2.size();j++){
    notmatchCount_list2++;
    }
    }

    break;
    }else {
    if(j == idList2.size()-1){
    notmatchCount_list1++;
    }

    notmatchCount_list2++;
    continue;
    }
    }
    }

    System.out.println((matchCount+notmatchCount_list1) == idList1.size());
    System.out.println((matchCount+notmatchCount_list2) == idList2.size());

    matchCount = 0;
    notmatchCount_list1 = 0;
    notmatchCount_list2 = 0;
    }
    }

    想的都是好
  • 相关阅读:
    使用css制作三角
    BZOJ3029: 守卫者的挑战
    Codeforces 442B. Andrey and Problem
    嘴巴题8 BZOJ2318: Spoj4060 game with probability Problem
    嘴巴题7 BZOJ1426: 收集邮票
    嘴巴题6 BZOJ3450JoyOI1952 Easy
    BZOJ1453: [Wc]Dface双面棋盘
    BZOJ2957: 楼房重建
    BZOJ4515: [Sdoi2016]游戏
    BZOJ3679: 数字之积
  • 原文地址:https://www.cnblogs.com/freezone/p/4920070.html
Copyright © 2020-2023  润新知