• 单词统计续


    package Word;
    
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.text.DecimalFormat;
    
    public class WordFind {
    
        public static void main(String[] args) {
            WordFind2[] word=new WordFind2[100];
            for(int i=0;i<100;i++) {
                word[i]=new WordFind2();
            }
            word[0].input(word);
            word[0].showAsc(word);
        }
    
    }
    
    class WordFind2{
        private char word;
        private int num;
        private static double time=0;
        public WordFind2() {
            word='0';
            num=1;
        }
        public static double getTime() {
            return time;
        }
        public char getWord() {
            return word;
        }
        public void setWord(char word) {
            this.word = word;
        }
        public int getNum() {
            return num;
        }
        public void setNum(int num) {
            this.num = num;
        }
        public void addnum() {
            num++;
        }
        public void input(WordFind2[] word) {
            String str;
            try {
                BufferedReader in=new BufferedReader(new FileReader("word.txt"));
                while((str = in.readLine())!=null) {
                    change(str,word);
                }
                in.close();
            }
            catch (IOException e) {
                System.out.println("缓冲区错误");
        }
        }
        private void change(String str, WordFind2[] word2) {
            char[] s1=str.toCharArray();
            for(int i=0,j=0;i<s1.length;i++) {
                if((s1[i]>=65&&s1[i]<=90)||(s1[i]>=97&&s1[i]<=122)) {
                    add(s1[i],word2);
                    time++;
                }
            }
            
        }
        private void add(char s, WordFind2[] word2) {
            int j=0;
            boolean f=false;
            for(int i=0;i<word2.length;i++) {
                if(word2[i].getWord()=='0') {f=true;j=i;break;}
                if(s==word2[i].getWord()) {word2[i].addnum();break;}
            }
            if(f==true) {
                word2[j]=new WordFind2();
                word2[j].setWord(s);
            }
        }
        void show(WordFind2[] word2) {
            DecimalFormat df = new DecimalFormat( "0.0000");
            double b=0;
            for(int i=0;word2[i].getWord()!='0';i++) {
                b=word2[i].getNum()/word2[i].getTime();
                System.out.println(word2[i].getWord()+"	"+df.format(b));
            }
        }
        void showAsc(WordFind2[] word2) {
            WordFind2 word=new WordFind2();
            for(int i=0;word2[i].getWord()!='0';i++) {
                //if(word2[i].getWord().equals("")) continue;
                for(int j=i+1;word2[j].getWord()!='0';j++) {
                        if(word2[i].getNum()<word2[j].getNum()) {
                            word.setWord(word2[i].getWord());
                            word.setNum(word2[i].getNum());
                            word2[i].setWord(word2[j].getWord());
                            word2[i].setNum(word2[j].getNum());
                            word2[j].setWord(word.getWord());
                            word2[j].setNum(word.getNum());
                        }
                    
                }
            }
            for(int i=0;word2[i].getWord()!='0';i++) {
                //if(word2[i].getWord().equals(""))continue;
                System.out.println(word2[i].getWord()+"	"+word2[i].getNum());//
            }
        }
    
    }

    package Word;
    
    import java.util.Scanner;
    
    public class Menu {
    
        public static void main(String[] args) {
            Scanner in =new Scanner(System.in);
            ShowMenu();
            int n=0;
            while((n=in.nextInt())!=4) {
                switch(n) {
                case 0:{
                    WordFind2[] word=new WordFind2[100];
                    for(int i=0;i<100;i++) {
                        word[i]=new WordFind2();
                    }
                    word[0].input(word);
                    word[0].showAsc(word);
                };break;
                case 1:{
                    WordFind3[] word=new WordFind3[999999];
                    for(int i=0;i<word.length;i++) {
                        word[i]=new WordFind3();
                    }
                    word[0].input(word);
                    word[0].showAsc(word);
                };break;
                case 2:{
                    System.out.println("请输入n的数值");
                    int n2=in.nextInt();
                    WordFind3[] word=new WordFind3[999999];
                    for(int i=0;i<word.length;i++) {
                        word[i]=new WordFind3();
                    }
                    word[0].input(word);
                    word[0].showAsc(word,n2);
                };break;
                default:System.out.println("输入错误!请重新输入");
                }
                ShowMenu();
            }
            
        }
        
        public static void ShowMenu() {
            System.out.println("请选择:");
            System.out.println("0:输出全部的字母");
            System.out.println("1:输出全部的单词");
            System.out.println("2:输出前n项单词");
            System.out.println("3:退出");
        }
    
    }
  • 相关阅读:
    BZOJ 1066 [SCOI2007]蜥蜴 (最大流)
    Codeforces 1092 D2 Great Vova Wall (Version 2) (栈)
    BZOJ 1046 [HAOI2007]上升序列(LIS + 贪心)
    牛客练习赛34 D little w and Exchange(归纳)
    BZOJ 1042 [HAOI2008]硬币购物(完全背包+容斥)
    GTMD并查集!
    2018icpc南京现场赛-G Pyramid(打标找规律+逆元)
    drwxr-xr-x 2 root root 4096 06-29 14:30 Test 分段解释
    Linux里面非常重要的目录
    点击 触发 事件 的 jQuery 写法样式
  • 原文地址:https://www.cnblogs.com/quyangzhangsiyuan/p/11071369.html
Copyright © 2020-2023  润新知