我在這裏有一個惱人的情況;其中我無法正確接受輸入。我總是通過Scanner
進行輸入,而我並不習慣於BufferedReader
。以Java輸入BufferedReader
INPUT FORMAT
First line contains T, which is an integer representing the number of test cases.
T cases follow. Each case consists of two lines.
First line has the string S.
The second line contains two integers M, P separated by a space.
例
Input:
2
AbcDef
1 2
abcabc
1 1
我迄今代碼:
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
int T= Integer.parseInt(inp.readLine());
for(int i=0;i<T;i++) {
String s= inp.readLine();
int[] m= new int[2];
m[0]=inp.read();
m[1]=inp.read();
// Checking whether I am taking the inputs correctly
System.out.println(s);
System.out.println(m[0]);
System.out.println(m[1]);
}
}
當輸入到示出的上述示例中,我得到以下輸出:
AbcDef
9
49
2
9
97
你的m [0] = inp.read();正在讀一個字節或其他東西。做一個readline到一個字符串中,並分割它以得到兩個字段,然後解析它們到整數。 –
'inp.read()'將讀取一個字符(16位)而不是字節(8位)。 –