• 学习随笔


    今天放一段做中国软件杯A08赛题的代码雏形

    public class ExampleA extends Thread{
        SynContainer container;
    
        public ExampleA(SynContainer container){
            this.container=container;
        }
    
        @Override
        public void run() {
            String filepath="D:\\中国软件杯\\因子5数据集\\part1.txt";
            BufferedReader bufferedReader=null;
            HashMap<Integer, Part> map=new HashMap<>();
            long startTime = System.currentTimeMillis();
            try {
    
                System.out.println("A开始导入数据");
                bufferedReader=new BufferedReader(new FileReader(filepath));
                String s;
    
                while ((s = bufferedReader.readLine()) != null){
                    int j=0;
                    int jj=0;
                    Part obj=new Part();
                    for (int i = 0; i < s.length(); i++) {
                        if(s.charAt(i)=='|'&&jj==0){
                            obj.PARTKEY=Integer.parseInt(s.substring(j,i));
                            j=i+1;
                            jj++;
                        }else if (s.charAt(i)=='|'&&jj==1){
                            obj.NAME=s.substring(j,i);
                            j=i+1;
                            jj++;
                        }else if(s.charAt(i)=='|'&&jj==2){
                            obj.MFGR=s.substring(j,i);
                            j=i+1;
                            jj++;
                        }else if(s.charAt(i)=='|'&&jj==3){
                            obj.BRAND=s.substring(j,i);
                            j=i+1;
                            jj++;
                        }else if(s.charAt(i)=='|'&&jj==4){
                            obj.TYPE=s.substring(j,i);
                            j=i+1;
                            jj++;
                        }else if(s.charAt(i)=='|'&&jj==5){
                            obj.SIZE=Integer.parseInt(s.substring(j,i));
                            j=i+1;
                            jj++;
                        }else if(s.charAt(i)=='|'&&jj==6){
                            obj.CONTAINER=s.substring(j,i);
                            j=i+1;
                            jj++;
                        }else if(s.charAt(i)=='|'&&jj==7){
                            obj.RETAILPRICE=Double.parseDouble(s.substring(j,i));
                            j=i+1;
                            jj++;
                        }else if(s.charAt(i)=='|'&&jj==8){
                            obj.COMMENT=s.substring(j,i);
                            j=i+1;
                            jj++;
                        }
                    }
                    map.put(obj.PARTKEY, obj);
                    obj=null;
                }
            }catch (IOException e){
                e.printStackTrace();
            }finally {
                try {
                    bufferedReader.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
    
            String filepath1="D:\\中国软件杯\\因子5数据集\\lineitem1.txt";
            BufferedReader bufferedReader1=null;
            HashMap<Integer, Lineitem> Lmap=new HashMap<>();
            try {
                bufferedReader1=new BufferedReader(new FileReader(filepath1));
                String s;
                int ii=1;
                while ((s = bufferedReader1.readLine()) != null){
                    int j=0;
                    int jj=0;
                    Lineitem lineitem=new Lineitem();
                    for (int i = 0; i < s.length(); i++) {
                        if(s.charAt(i)=='|'&&jj==0){
                            lineitem.ORDERKEY=Integer.parseInt(s.substring(j,i));
                            j=i+1;
                            jj++;
                        }else if (s.charAt(i)=='|'&&jj==1){
                            lineitem.PARTKEY=Integer.parseInt(s.substring(j,i));
                            j=i+1;
                            jj++;
                        }else if(s.charAt(i)=='|'&&jj==2){
                            lineitem.SUPPKEY=Integer.parseInt(s.substring(j,i));
                            j=i+1;
                            jj++;
                        }else if(s.charAt(i)=='|'&&jj==3){
                            lineitem.LINENUMBER=Integer.parseInt(s.substring(j,i));
                            j=i+1;
                            jj++;
                        } else if(s.charAt(i)=='|'&&jj==4){
                            lineitem.QUANTITY=Integer.parseInt(s.substring(j,i));
                            j=i+1;
                            jj++;
                        } else if(s.charAt(i)=='|'&&jj==5){
                            lineitem.EXTENDEDPRICE=Double.parseDouble(s.substring(j,i));
                            j=i+1;
                            jj++;
                            break;
                        }
    
                    }
                    Lmap.put(ii,lineitem);
                    lineitem=null;
                    ii++;
                }
            }catch (IOException e){
                e.printStackTrace();
            }finally {
                try {
                    bufferedReader1.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
                System.out.println("数据导入结束");
                long endTime1 = System.currentTimeMillis();
                //打印
                long time1= TimeUnit.MILLISECONDS.toSeconds((endTime1 - startTime));
                System.out.println("A程序导入数据时间:" + time1 + "s");
            }
    
            System.out.println("输入S开始查询:");
            Scanner scanner=new Scanner(System.in);
            String s=scanner.nextLine();
    
            long startTime1 = System.currentTimeMillis();
            Total[][] total=new Total[5][5];
            for (int i = 1; i <=5 ; i++) {
                for (int j=1;j<=5;j++){
                    total[i-1][j-1]=new Total("",0);
                    total[i-1][j-1].BRAND="Brand#"+i+j;
                    total[i-1][j-1].QUANTITY=0;
                }
            }
    //        System.out.println("开始遍历");
            int count=0;
            for(Integer id:Lmap.keySet()){
                if(map.get(Lmap.get(id).PARTKEY)!=null) {
                    for (int i=0;i<5;i++) {
                        for (int j=0;j<5;j++) {
                            if (map.get(Lmap.get(id).PARTKEY).BRAND.equals(total[i][j].BRAND)) {
                                total[i][j].QUANTITY = total[i][j].QUANTITY + Lmap.get(id).EXTENDEDPRICE;
                                count++;
                                break;
                            }
                        }
                        if(count==1){
                            break;
                        }
                    }
    
                }
            }
    //        System.out.println("遍历结束");
            ArrayList<Total> arrayList=new ArrayList<>();
            for (int i = 0; i <5 ; i++) {
                for (int j=0;j<5;j++){
                   arrayList.add(total[i][j]);
                }
            }
    
            Res res=new Res();
            res.name="线程A";
            res.code=200;
            res.err="查询成功";
            res.dataList=arrayList;
            container.submit(res);
    
            long endTime = System.currentTimeMillis();
            //打印
            long time= TimeUnit.MILLISECONDS.toSeconds((endTime - startTime1));
            System.out.println("A程序运行时间:" + time + "s");
        }
    }
    View Code
  • 相关阅读:
    Structured streaming
    streaming窗口操作
    scala伴生对象,apply()及单例
    storm集成kafka
    solr简易安装配置
    拦路雨偏似雪花,饮泣的你冻吗?--稍瑞,我是关键字过滤器
    我存在,你深深的循环里--从反射看JSON死循环
    ueditor:原谅我这一生不羁放纵爱独特
    或许你不知道(2):LinkedList
    自定义负载均衡
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/16282599.html
Copyright © 2020-2023  润新知