Scanner sc = new Scanner(System.in); String str = sc.nextLine(); if (str.length() <= 1 || str.length() > 100) { System.out.println(0); } else { int count = 0; for (int i = 0; i < str.length(); i++) { for (int j = i; j < str.length(); j++) { // 判断两个端点 再判断区间是否为回文 且 每个字母都属于 list if (isCC(str.charAt(i)) && str.charAt(i) == str.charAt(j)) { if (j - i >= 1) { for (int k = i, l = j; k <= l; k++, l--) { if (str.charAt(k) == str.charAt(l) && isCC(str.charAt(k))&& isCC(str.charAt(l))) { if (k == l) { count++; } else if (k + 1 == l) { count++; } } } } } } } System.out.println(count); } } private static boolean isCC(char c) { char[] cc = new char[]{'A','H','I','M','O','T','U','V','W','X','Y'}; for (int i = 0; i < cc.length; i++) { if (cc[i] == c) { return true; } } return false; } 我这个也是一个用例都无法通过,但是自测可以,懵了
点赞 1

相关推荐

05-01 22:41
中南大学 Java
点赞 评论 收藏
分享
牛客网
牛客企业服务