Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Java by registered user SKYDOS ( 17 years ago )
import java.util.*;
import java.io.*;
public class Main {
public static void main (String[] args) throws IOException {
new Main().run();
}
public int convert (char c) {
String tmp = "0123456789";
int k;
for (k=0; k<10; k++)
if (c==tmp.charAt(k)) {
break;
};
return k;
}
public void run() throws IOException {
Scanner sc = new Scanner (new File ("input.txt"));
PrintWriter pw = new PrintWriter (new File ("output.txt"));
String line = "";
int n = sc.nextInt();
int[][] board = new int[n][n];
char[][] res = new char[n][n];
for (int i=0; i<n; i++) {
line = sc.next();
for (int j=0; j<n; j++) {
board[i][j] = convert (line.charAt(j));
res[i][j] = '#';
}
}
for (int i=1; i<n; i++) {
board[0][i] = board[0][i]+board[0][i-1];
res[0][i] = 'L';
}
for (int j=1; j<n; j++) {
board[j][0] = board[j][0]+board[j-1][0];
res[j][0] = 'U';
}
for (int i=1; i<n; i++) {
for (int j=1; j<n; j++) {
if (board[i][j-1]<board[i-1][j]) {
board[i][j] = board[i][j]+board[i][j-1];
res[i][j] = 'L';
} else {
board[i][j] = board[i][j]+board[i-1][j];
res[i][j] = 'U';
}
}
}
int x=n-1, y=n-1;
do {
switch (res[x][y]) {
case 'U': res[x][y] = '#'; x--; break;
case 'L': res[x][y] = '#'; y--; break;
}
if (x==0 && y==0) break;
} while (true);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (res[i][j]!='#') pw.print (".");
else pw.print ("#");
}
pw.print ("\n");
}
pw.close();
}
}
Revise this Paste