• 单词接龙


    package mypackage;
    
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Scanner;
    
    public class main {
        static String []w=new String[1000];
        static char [][]wa=new char[1000][2];
        static int i=0;
        
        static void ward() throws IOException 
        {
            HashMap<String, Integer>mp = new HashMap<>();
            mp.put("jack", 1);
            mp.put("Tom", 2);
            mp.put("rose", 3);
            mp.put("jack",4);
            try (BufferedReader in = new BufferedReader(new FileReader("C:\Users\\xxoo\Desktop\input1.txt"))
                    ){
                    String line;
                    int c = 0;
                    while(null != (line = in.readLine())) {
                        
                        String[] words = line.split("\W");//单词的边界                
                        for(String w : words) {
                            if(w.trim().length() == 0) continue;
    //                        if(w.trim().length() == 1) {
    //                            //长度为1
    //                            char cc = w.charAt(0);
    //                            if(!Character.isLetterOrDigit(c)) {
    //                                continue;
    //                            }
    //                        }
                            w = w.toLowerCase();//不分大小写的统计                    
                            if(!mp.containsKey(w)) {
                                mp.put(w, 1);
                            }else {
                                int n = mp.get(w);
                                mp.put(w, n+1);
                            }                    
                        }
                        
                    }
                    for(String key : mp.keySet()) {
                        int v = mp.get(key);
    //                    System.out.println(key+"	"+v);          
                        w[i]=key;
                        i++;
                        }
                    
                } catch (Exception e) {
                    // TODO: handle exception
                }
        }    
        
        static void sw() 
        {
            for(int j=0;j<i;j++)
            {
                char[] chs = w[j].toCharArray();
                wa[j][0]=chs[0];
                for(Character ch:chs){
                    wa[j][1]=ch;
                }        
    //            System.out.print(wa[j][0]);
    //            System.out.println(wa[j][1]);
            }
        }
        
        public static void jielong()
        {    
            System.out.println(w[0]);
            for(int x=1,y=0;x<=i;x++)
            {
                if(wa[y][1]==wa[x][0])
                {
                    System.out.println(w[x]);
                    y=x;
                }
            }
        }
        
    //    static Boolean p(int[] a,int b,int c)
    //    {
    //        for(int x=0;x<=b;x++)
    //        {
    //            if(a[x]==c)
    //            {
    //                break;
    //            }
    //            if(x==b)
    //            {
    //                return true;
    //            }
    //        }
    //        return false;
    //    }
        
        public static void main(String[] args) throws IOException {
            ward();
            sw();
            jielong();
            
            
            }
    }

  • 相关阅读:
    PyQt5经典案例
    JS实现深拷贝(解决循环引用等问题)
    React/Vue里的key到底有什么用?看完这篇你就知道了!(附demo代码)
    linux盘符操作命令
    Ubuntu20.04下安装opencv for C++
    数字图像处理-python随机噪声、高斯噪声和椒盐噪声实现
    数字图像处理-(1)pyqt页面
    数字图像处理-Python读取BMP文件
    docker笔记
    CentOS7安装GO
  • 原文地址:https://www.cnblogs.com/sonofdemon/p/10994949.html
Copyright © 2020-2023  润新知