zoukankan      html  css  js  c++  java
  • 计算随意无序字符串中的最大有序串

    private void compare() {
            //定义个无序字符串
            String str = "sdifsdafsdabfwqicweedio";
            //置于hashset去重
            HashSet<Character> set = new HashSet<Character>();
            for (int i = 0; i < str.length(); i++) {
                set.add(str.charAt(i));
            }
            System.out.println("set=" + set);
            Object[] list = set.toArray();
            Object temp = "";
            //冒泡排序
            for (int i = 0; i < list.length; i++) {
                for (int j = i; j < list.length; j++) {
                    char ch = (Character) list[i];
                    char ca = (Character) list[j];
                    if (ch > ca) {
                        temp = list[i];
                        list[i] = list[j];
                        list[j] = temp;
                    }
                }
            }
             //此for为了方便展示排序后的数组的结果
            String result = "";
            for (int i = 0; i < list.length; i++) {
                result += "" + list[i];
            }
            System.out.println("有序串=" + result);
        }

  • 相关阅读:
    HOOK劫持自己
    迷宫程序
    文件检索
    查看typedef类型
    位运算计算加法
    mfc进制转换
    递归进制转换_strrev
    printf("%x",12)//按十六进制输出
    MFC补码原码反码转换工具
    basename
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/7159388.html
Copyright © 2011-2022 走看看