我试图提交关于 UVa 的扫雷问题(http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1130)
样本输入:
4 4
*...
....
.*..
....
样本输出:
*100
2210
1*10
1110
我在 NetBeans 上开发了代码。我已经对其进行了测试并且工作正常,但是当我尝试在 UVa 上提交它时,它会导致提交的答案错误。
我有两个问题:1)我的代码有什么问题?2) 为 UVa 编码时我应该使用什么以及不应该使用什么?
-如果我应该遵循不同的标准,请提出建议
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
String REGEX_WHITESPACE = "\\s+";
String cleanLine = line.trim().replaceAll(REGEX_WHITESPACE, " ");
String[] numChar = cleanLine.split(REGEX_WHITESPACE);
int n = new Integer(numChar[0]).intValue();
int m = new Integer(numChar[1]).intValue();
char[][] mine = new char[n][m];
char[] curLine;
for(int i=0;i<n;i++){
line=reader.readLine();
cleanLine = line.trim().replaceAll(REGEX_WHITESPACE, " ");
curLine = cleanLine.toCharArray();
if(curLine.length==m){
mine[i]=curLine;
}
}
int starsCount=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(mine[i][j]=='*'){
System.out.print('*');
}
else{
try {
if (mine[i][j - 1] == '*') {
starsCount++;
}
} catch (Exception e) {
}
try {
if (mine[i][j + 1] == '*') {
starsCount++;
}
} catch (Exception e) {
}
try {
if (mine[i-1][j] == '*') {
starsCount++;
}
} catch (Exception e) {
}
try {
if (mine[i+1][j] == '*') {
starsCount++;
}
} catch (Exception e) {
}
try {
if (mine[i-1][j - 1] == '*') {
starsCount++;
}
} catch (Exception e) {
}
try {
if (mine[i-1][j + 1] == '*') {
starsCount++;
}
} catch (Exception e) {
}
try {
if (mine[i+1][j - 1] == '*') {
starsCount++;
}
} catch (Exception e) {
}
try {
if (mine[i+1][j + 1] == '*') {
starsCount++;
}
} catch (Exception e) {
}
if(j==m-1){
System.out.println(starsCount);
}
else{
System.out.print(starsCount);
}
starsCount=0;
}
}
}
}
}