393A Nineteen cf题解(java)

开始出错原因:对n计算错误,误以为1+(letter[‘n’ - ‘a’]-1) / 2,应该是(letter[‘n’ - ‘a’]-1) / 2;

import java.util.Scanner;


/**
 * Main.注意考虑到边界情况与特殊情况
 * @author : cxc
 **/
public class Main {
  public static void main(String[] args) {
    Scanner myin = new Scanner(System.in,"utf-8");
    String mystr = myin.next();
    //逐个字符计数,求倍数
    //nineteen,3n,3e,1i,1t,
    char[] mychar = mystr.toCharArray();
    int[] letter = new int[26];
    for (int i = 0; i < mychar.length; i++) {
      letter[mychar[i] - 'a']++;
    }
    int[] temp = new int[4];
    temp[0] = (letter['n' - 'a']-1) / 2;
    temp[1] = letter['e' - 'a'] / 3;
    temp[2] = letter['i' - 'a'];
    temp[3] = letter['t' - 'a'];
    int mintemp = Integer.MAX_VALUE;
    for (int j = 0; j < temp.length; j++) {
      if (temp[j] < mintemp) {
        mintemp = temp[j];
      }
    }
    System.out.println(mintemp);
  }
}

发布了96 篇原创文章 · 获赞 56 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/JAck_chen0309/article/details/103571149