hihoCoder太阁最新面经算法竞赛5 register

Ended

Participants:118

Verdict:Accepted
Score:100 / 100
Submitted:2016-06-21 20:37:12

Lang:Java

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
public class Main {
    public static void main(String[] argsthrows Exception {
        Scanner in = new Scanner(System.in);
        char[] queue = in.next().toCharArray();
        in.close();
        if (queue.length == 1) { // 1
            System.out.println(queue[0]);
            return;
        }
        int[] l = new int[26];
        for (int i = 0i < queue.length++i) {
            l[queue[i- 'a']++;
        }
        for (int i = 0i < l.length++i) {
            if (2 * l[i> queue.length + 1) {
                System.out.println("INVALID");
                return;
            }
        }
        StringBuffer result = new StringBuffer();
        int[] top = getTop2(l);
        while (true) {
            char ca = (char) (top[0+ 'a');
            char cb = (char) (top[1+ 'a');
            while (l[top[0]] != 0 && l[top[1]] != 0) {
                result.append(ca + "" + cb);
                l[top[0]]--;
                l[top[1]]--;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX