题解 | #字符串合并处理#

字符串合并处理

https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str_1 = in.next();
        String str_2 = in.next();

        Map<Character, Character> tr = new HashMap<Character, Character>();
        tr.put('0', '0');
        tr.put('1', '8');
        tr.put('2', '4');
        tr.put('3', 'C');
        tr.put('4', '2');
        tr.put('5', 'A');
        tr.put('6', '6');
        tr.put('7', 'E');
        tr.put('8', '1');
        tr.put('9', '9');
        tr.put('a', '5');
        tr.put('b', 'D');
        tr.put('c', '3');
        tr.put('d', 'B');
        tr.put('e', '7');
        tr.put('f', 'F');
        tr.put('A', '5');
        tr.put('B', 'D');
        tr.put('C', '3');
        tr.put('D', 'B');
        tr.put('E', '7');
        tr.put('F', 'F');

        //第一步
        String str = str_1 + str_2;
        char[] cs_str = str.toCharArray();

        //第二步
        char[] cs_str_1 = new char[str.length() / 2 + str.length() % 2];
        char[] cs_str_2 = new char[str.length() / 2];

        int index_1 = 0;
        int index_2 = 0;
        for (int i = 0; i < str.length(); i++) {
            if (i % 2 == 0) {
                cs_str_1[i / 2] = cs_str[i];
            } else {
                cs_str_2[(i - 1) / 2] = cs_str[i];
            }
        }

        Arrays.sort(cs_str_1);
        Arrays.sort(cs_str_2);

        int index_1_1 = 0;
        int index_1_2 = 0;
        for (int i = 0; i < str.length(); i++) {
            if (i % 2 == 0) {
                cs_str[i] = cs_str_1[i / 2];
            } else {
                cs_str[i] = cs_str_2[(i - 1) / 2];
            }
        }

        //第三步
        for (int i = 0; i < str.length(); i++) {
            char c = cs_str[i];
            if ((c >= '0' && c <= '9') ||
                    (c >= 'A' && c <= 'F') ||
                    (c >= 'a' && c <= 'f')) {
                cs_str[i] = tr.get(c);;
            }
        }

        System.out.println(new String(cs_str));
    }
}

全部评论

相关推荐

08-29 19:44
门头沟学院 Java
wish233:很强了,加上这个学历,一点小建议就是可以把你的项目做一个压测,比如说你的RPC,可以对比一下和http相比性能怎么样。还有你的秒杀,一定要自己压测一遍,确保不会出现数据不一致的问题。还有就是对于分布式锁的粒度一定要理清楚,这个很容易被问到。
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务