Skip to content

Instantly share code, notes, and snippets.

@Naba0123
Last active June 11, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naba0123/fd8fb3a891e8c30e08ac to your computer and use it in GitHub Desktop.
Save Naba0123/fd8fb3a891e8c30e08ac to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
// 入力
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String rs = "";
rs = br.readLine();
String[] xyLength = rs.split(" ");
int xLength = Integer.parseInt(xyLength[0]);
int yLength = Integer.parseInt(xyLength[1]);
int[][] xy = new int[xLength][yLength];
int y_ = 0;
while ((rs = br.readLine()) != null) {
String[] y = rs.split(" ");
for (int i = 0; i < y.length; i++) {
int x_ = Integer.parseInt(y[i]);
// 入力が2の場合は0にする
xy[i][y_] = (x_ == 2) ? 0 : x_;
}
y_++;
}
// 処理
for (int i = 0; i < xLength; i++) {
for (int j = yLength - 1; j > 0; j--) {
if (xy[i][j] == 1) {
continue;
} else {
for (int k = j; k >= 0; k--) {
if (xy[i][k] == 0) {
continue;
} else {
// ここで落とす処理
xy[i][k] = 0;
xy[i][j] = 1;
k = 0;
}
}
}
}
}
// 出力
for (int i = 0; i < yLength; i++) {
for (int j = 0; j < xLength; j++) {
System.out.print(xy[j][i]);
if (j != xLength - 1)
System.out.print(" ");
}
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment