1、subString方法截取字符串是按照下标开始的。
2、在读入T之后,如果直接用inScanner.nextLine()读取字符串的话,会把回车也读成一个字符串,这个地方需要像c中的getchar()一样把这个回车给吸收掉。
3、在比较的时候,不能直接比较good,因为no good本身就包含一个good。
4、对于XXX Xno good这样的数据需要注意,如果直接截取后面七位就会得到一个no good,所以这种情况需要判断no前面是不是空格。
import java.util.*;
class result {
StringBuffer s = new StringBuffer();
public void setS(String s) {
this.s.append(s);
}
public boolean getS() {
String ssString = new String();
if (s.length() < 8)
return false;
char c = s.charAt(s.length() - 8);
if (c != ' ')
return false;
ssString = s.substring(s.length() - 7);
return ssString.equals("no good");
}
}
public class Main {
public static void main(String[] args) {
Scanner inScanner = new Scanner(System.in);
int[][] a;
a = new int[2][105];
int T;
while (inScanner.hasNextInt()) {
T = inScanner.nextInt();
String string = new String();
string = inScanner.nextLine();
if (T == 0)
break;
int temp = (T + 1) / 2;
for (int i = 1; i <= temp; i++) {
System.out.print(i + " ");
}
System.out.println("Score");
for (int i = 0; i < 2; i++) {
for (int j = 0; j <= temp; j++)
a[i][j] = -1;
}
result sss = new result();
for (int i = 0; i < T; i++) {
sss.setS(inScanner.nextLine());
if (sss.getS() == true) {
if (i % 2 == 1)
a[1][i / 2] = 0;
else
a[0][i / 2] = 0;
} else {
if (i % 2 == 1)
a[1][i / 2] = 1;
else
a[0][i / 2] = 1;
}
}
for (int i = 0; i < 2; i++) {
int cnt = 0;
for (int j = 0; j < temp - 1; j++) {
if (a[i][j] == 0)
System.out.print("X" + " ");
else {
System.out.print("O" + " ");
cnt++;
}
}
if (a[i][temp - 1] == 0)
System.out.print("X" + " ");
else if (a[i][temp - 1] == 1) {
System.out.print("O" + " ");
cnt++;
} else
System.out.print("-" + " ");
System.out.println(cnt);
}
}
}
}