POJ 3250:字母重排

AC CODE:

import java.util.Scanner;


public class Main {

    private static char[] ASCII = {
        'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
    };
    private static String getString() {
        Scanner input = new Scanner(System.in);
        return input.nextLine();
    }
    
    private static boolean isLetter(char c) {
        if (('a' <= c) && (c <= 'z')) {
            return true;
        }
        return false;
    }
    
    private static int[] getSortArray(String str, int[] letters) {
        for (int i = 0; i < str.length(); i++) {
            if (isLetter(str.charAt(i))) {
                letters[str.charAt(i) - 'a']++;
            }
        }
        
        return letters;
    }
    
    public static void main(String[] args) {
        String str = getString();
        
        int[] letters = new int[26];
        letters = getSortArray(str, letters);
        
        for (int i = 0; i < letters.length; i++) {
            for (int j = 0; j < letters[i]; j++) {
                System.out.print(ASCII[i] + "");
            }
        }
        System.out.print("\n");
    }

}

 

你可能感兴趣的:(poj)