UVA 10008 Java

  1. import java.util.*;
  2.  
  3. public class main{
  4. public static void main(String[] args) {
  5. Scanner sc=new Scanner(System.in);
  6. int lines = sc.nextInt();
  7. sc.nextLine();
  8. int[] count = new int[26];
  9. int max = 0;
  10. for(int i = 0; i < lines; i++)
  11. {
  12. String str = sc.nextLine().toLowerCase();
  13. for(int j = 0; j < str.length(); j++)
  14. {
  15. char ch = str.charAt(j);
  16. if(ch >= 97 && ch <= 122)
  17. if(++count[ch - 97] > max)
  18. max = count[ch - 97];
  19. }
  20. }
  21. for(int i = max; i > 0; i--)
  22. for(int j = 0; j < 26; j++)
  23. if(i == count[j])
  24. System.out.println(String.format("%c %d", (char)(j + 65), i));
  25. }
  26. };
  27.  

留言

這個網誌中的熱門文章

C# 井字遊戲