UVA 10008 Java

import java.util.*;

public class main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int lines = sc.nextInt();
    sc.nextLine();
    int[] count = new int[26];
    int max = 0;
    for(int i = 0; i < lines; i++)
    {
    	String str = sc.nextLine().toLowerCase();
    	for(int j = 0; j < str.length(); j++)
    	{
    		char ch = str.charAt(j);
    		if(ch >= 97 && ch <= 122)
    			if(++count[ch - 97] > max)
    				max = count[ch - 97];
    	}
    }
    for(int i = max; i > 0; i--)
    	for(int j = 0; j < 26; j++)
    		if(i == count[j])
    			System.out.println(String.format("%c %d", (char)(j + 65), i));
  }
};

留言

這個網誌中的熱門文章

UVA 11321 Java