2029.Palindromes _easy version
解题思路:
判断字符串左边第i位的字符与右边第i位的字符是否相同。
实现代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while(s.hasNext()) {
int n = s.nextInt();
String w = s.nextLine();
while(n-->0) {
w = s.nextLine();
int a = 0;
for (int i = 0; i < w.length()/2; i++) {
if(w.charAt(i)==w.charAt(w.length()-i-1)) { //左边第i位字符和右边第i位比较
a=1;
}else {
a=2;
}
}
if(a == 1) {
System.out.println("yes");
}else if(a == 2){
System.out.println("no");
}
}
}
}
}
2030.汉字统计![在这里插入图片描述](https://img-blog.csdnimg.cn/758209abd9e642cfb4f3bb7b0abf1ce5.png#pic_center)
解题思路:
该题只需要知道汉字的ASCII码,百度能查到。
实现代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
while(s.hasNext()) {
int n = s.nextInt();
String w = s.nextLine();
while(n-->0) {
w = s.nextLine();
int a = 0; //汉字个数
for (int i = 0; i < w.length(); i++) {
if(w.charAt(i)<0 || w.charAt(i)>255) { //判断字符的ASCII码是否符合汉字ASCII码的范围
a++;
}
}
System.out.println(a);
}
}
}
}