1.小红背单词
public class Main1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
int count = 1;
HashMap<String, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
String word = scanner.nextLine();
int value = map.getOrDefault(word, 0) + 1;
map.put(word,value);
if (value == count){
map.put(word,Integer.MIN_VALUE);
count++;
}
}
System.out.println(count-1);
}
}
2.判断回文串
public class Main2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
for(int i = 0;i < n;i++){
String str = scanner.nextLine();
char[] strArray = str.toCharArray();
boolean is = method(strArray);
String result = is ? "YES" : "NO";
System.out.println(result);
}
}
private static boolean method(char[] strArray) {
ArrayList<Character> list = new ArrayList<>();
for (int i = 0; i < strArray.length; i++) {
if (strArray[i] == 'm') {
list.add('u');
list.add('u');
}else if (strArray[i] == 'w') {
list.add('v');
list.add('v');
}else if (strArray[i] == 'b' || strArray[i] == 'p' || strArray[i] == 'q' || strArray[i] == 'd') {
list.add('b');//p q d 都行
}else if (strArray[i] == 'u' || strArray[i] == 'n') {
list.add('u');
}else {
list.add(strArray[i]);
}
}
for (int i = 0, j = list.size() - 1; i < j; i++, j--) {
if (list.get(i) != list.get(j)) {
return false;
}
}
return true;
}
}