牛客网java_牛客网笔试Java输入输出救命模版
被牛客網筆試輸入輸出坑過的看過來吧!
系統給你的輸入文本是這樣的,第一行兩個數字是 矩陣的 行數 列數,第二行是矩陣搜索起點的坐標,剩下的行是矩陣里面的內容。如果是兩個test case 就是這樣的文本:
5 6
2 1
######
#1234#
#-####
#FZYG#
######
5 6
2 1
######
#1234#
#----#
#FZYG#
######
我們可以這樣輸入并處理:
import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()){
int m = sc.nextInt();
int n = sc.nextInt();
System.out.println(m);
System.out.println(n);
char[][] matrix = new char[m][n];
int x = sc.nextInt();
int y = sc.nextInt();
System.out.println(x);
System.out.println(y);
sc.nextLine(); // 這一行非常重要!!!! nextInt 完了之后一定要加這個不然會出錯!!!
for (int i=0; i
String line = sc.nextLine();
matrix[i] = line.toCharArray();
System.out.println(line);
}
}
}
}
坑爹的是,這個while在自己本地的編譯器上是停不下來的,但是牛客網上可以,所以你要調試,還是在牛客網上調試把。
總結
以上是生活随笔為你收集整理的牛客网java_牛客网笔试Java输入输出救命模版的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转折点:移动互联网时代的商业法则
- 下一篇: Idea中变量的下划线