zoukankan      html  css  js  c++  java
  • 字符串排序, 华为

    import java.util.*;
    public class Main {
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            while(sc.hasNext()){
                char[] a = sc.nextLine().toCharArray();
                List<Integer[]> list = new ArrayList<>();
                int idx = 0;
                for(int i=0; i < a.length; i++) {
                    if((a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z')) {
                        list.add(new Integer[] {(int)a[i], idx++});
                    }
                }
                Collections.sort(list, new Comparator<Integer[]>(){
                    public int compare(Integer[] o1, Integer[] o2) {
                        int x = o1[0] >= 'a' ? o1[0] -32 : o1[0];
                        int y = o2[0] >= 'a' ? o2[0] -32 : o2[0];
                        return x == y ? o1[1] - o2[1] : x - y;
                    }
                });
                idx = 0;
                for(int i=0; i < a.length; i++) {
                    if((a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z')) {
                        int t = list.get(idx++)[0];
                        a[i] = (char) t;
                    }
                }
                System.out.println(String.valueOf(a));
            }
        }
    }
    
  • 相关阅读:
    基于RBAC的权限设计模型
    RBAC用户权限管理数据库设计
    系统多语言实践(二)
    多语言系统的数据库设计
    系统多语言实践(一)
    企业后台模板
    MYSQL
    JS,Jquery
    BootStrap
    KindEditor
  • 原文地址:https://www.cnblogs.com/lixyuan/p/13280760.html
Copyright © 2011-2022 走看看