9月2日美团后端笔试
请教一下 第2题为啥死活过不了
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
//处理输入 获得 n\m
int n = in.nextInt();
int m = in.nextInt();
//处理多的换行符号
in.nextLine();
//读取n行字符串
String[] strings = new String[n];
for (int i = 0; i < n; i++) {
strings[i] = in.nextLine();
}
String theWord = "meituan";
boolean found = false;
int index = 0;
for (int i = 0; i < n; i++) {
if (strings[i].contains(String.valueOf(theWord.charAt(index)))) {
index++;
}
if (index == theWord.length() - 1) {
found = true;
break;
}
}
//进行输出
if (found) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
```
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
//处理输入 获得 n\m
int n = in.nextInt();
int m = in.nextInt();
//处理多的换行符号
in.nextLine();
//读取n行字符串
String[] strings = new String[n];
for (int i = 0; i < n; i++) {
strings[i] = in.nextLine();
}
String theWord = "meituan";
boolean found = false;
int index = 0;
for (int i = 0; i < n; i++) {
if (strings[i].contains(String.valueOf(theWord.charAt(index)))) {
index++;
}
if (index == theWord.length() - 1) {
found = true;
break;
}
}
//进行输出
if (found) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
```
全部评论
蹲
可能是因为你YES和NO写错了,我记得是全大写
相关推荐
11-08 13:58
门头沟学院 Java 点赞 评论 收藏
分享