2016年7月2日 星期六

Q10008: What's Cryptanalysis


https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=12&problem=949&mosmsg=Submission+received+with+ID+17608041

import java.util.Arrays;
import java.util.Scanner;

public class Main {

 public static void main(String[] args) {
  Scanner scn = new Scanner(System.in);
  int n = Integer.parseInt(scn.nextLine()), ans[] = new int[26], j, i,max=0;
  for (i = 0; i < n; i++) {
   String str = scn.nextLine().toUpperCase();
   char arr[] = str.toCharArray();
   for (j = 0; j < arr.length; j++) {
    if (arr[j] >= 'A' && arr[j] <= 'Z') {
     ans[arr[j] - 'A']++;
     if(max<ans[arr[j]-'A'])max=ans[arr[j]-'A'];
    }
   }
  }
  for(j=max;j>0;j--){
   for(int k=0;k<ans.length;k++)
    if(ans[k]==j)System.out.printf("%c %d\n",k+'A',ans[k]);
  }

 }

 /* 
    題目:Q10008: What's Cryptanalysis
    作者:1010
    時間:西元 2016 年 7 月 */

}


困難度 
nextInt後面不能直接接nextLine要int n=Integer.parseInt(scn.nextLine())
跟c一樣 如果整數後面讀字串他會抓到暫存區裡的換行字元

沒有留言:

張貼留言