문제 확인하기
2. 정답 코드 (Java, memory: 14200KB, time: 120ms)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
int n = Integer.parseInt(reader.readLine());
if (n == 0) {
break;
}
String[] lines = new String[n];
for (int i = 0; i < n; i++) {
lines[i] = reader.readLine();
}
int column = findBallColumn(lines);
System.out.println(column);
}
reader.close();
}
private static int findBallColumn(String[] lines) {
int lineIndex = 0;
int columnIndex = 0;
while (lineIndex < lines.length && columnIndex < 100) {
if (lines[lineIndex].length() <= columnIndex) {
lineIndex++;
continue;
}
if (lines[lineIndex].charAt(columnIndex) == ' ') {
lineIndex++;
} else {
columnIndex++;
}
}
return columnIndex + 1;
}
}