From 8a42d6bf876decf442ff3d4824aada02e801ac88 Mon Sep 17 00:00:00 2001 From: anakamura Date: Tue, 8 Jul 2025 11:59:05 +0900 Subject: [PATCH 1/4] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB136?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anakamura/src/B136.java | 102 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 anakamura/src/B136.java diff --git a/anakamura/src/B136.java b/anakamura/src/B136.java new file mode 100644 index 0000000..5006899 --- /dev/null +++ b/anakamura/src/B136.java @@ -0,0 +1,102 @@ +package anakamura.src; + +import java.util.Scanner; + +public class B136 { + public static void main(String[] args) { + + final Scanner sc = new Scanner(System.in); + + final int numberOfMoves = sc.nextInt(); // 移動回数 + final int colsOfMatrix = sc.nextInt(); // 縦の列の数 + final int rowsOfMatrix = sc.nextInt(); // 横の列の数 + + final int startCols = sc.nextInt(); // 自分の縦の場所 + final int startRows = sc.nextInt();// 自分の横の場所 + + final String movedRoute = sc.next();// 移動経路 + + // 文字列を1文字ずつに分割する + char[] array = new char[movedRoute.length()]; + for (int i = 0; i < movedRoute.length(); i++) { + char movement = (movedRoute.charAt(i)); + array[i] = movement; + } + Position potion = new Position(startRows, startCols); + + // 前からi列目左からj列目に座っているクラスメイトがくれるチョコレートの数 + final int[][] matrix = new int[colsOfMatrix][rowsOfMatrix]; + for (int i = 0; i < colsOfMatrix; i++) { + for (int j = 0; j < rowsOfMatrix; j++) { + matrix[i][j] = sc.nextInt(); + } + } + sc.close(); + + int chocolateNum[] = new int[numberOfMoves]; + // 1文字ずつ条件にあったメソッドを動かす + for (int i = 0; i < numberOfMoves; i++) { + switch (array[i]) { + case 'F': + potion.moveFront(); + break; + case 'B': + potion.moveBack(); + break; + case 'L': + potion.moveLeft(); + break; + case 'R': + potion.moveRight(); + break; + } + // チョコの個数を記述 + chocolateNum[i] = matrix[potion.getCols()][potion.getRows()]; + } + // 出力 + for (int num : chocolateNum) { + System.out.println(num); + } + } + +} + + +class Position { + private int rows, cols; + + public Position(int initialRows, int initialCols) { + this.cols = initialCols - 1; + this.rows = initialRows - 1; + + } + + public int getRows() { + return rows; + } + + public int getCols() { + return cols; + + } + + // 前方向に移動する場合 + public void moveFront() { + cols -= 1; + } + + // 後方向に移動する場合 + public void moveBack() { + cols += 1; + } + + // 左方向に移動する場合 + public void moveLeft() { + rows -= 1; + } + + // 右方向に移動する場合 + public void moveRight() { + rows += 1; + } +} -- GitLab From e205d65096574f4dbcf42b3059dea24ba04caba4 Mon Sep 17 00:00:00 2001 From: anakamura Date: Tue, 8 Jul 2025 16:24:40 +0900 Subject: [PATCH 2/4] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB136?= =?UTF-8?q?=E3=81=AE=E8=AA=B2=E9=A1=8C=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anakamura/src/B136.java | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/anakamura/src/B136.java b/anakamura/src/B136.java index 5006899..9cbae7b 100644 --- a/anakamura/src/B136.java +++ b/anakamura/src/B136.java @@ -17,44 +17,44 @@ public class B136 { final String movedRoute = sc.next();// 移動経路 // 文字列を1文字ずつに分割する - char[] array = new char[movedRoute.length()]; + char[] arrayOfChar = new char[movedRoute.length()]; for (int i = 0; i < movedRoute.length(); i++) { char movement = (movedRoute.charAt(i)); - array[i] = movement; + arrayOfChar[i] = movement; } - Position potion = new Position(startRows, startCols); + Position position = new Position(startRows, startCols); // 前からi列目左からj列目に座っているクラスメイトがくれるチョコレートの数 final int[][] matrix = new int[colsOfMatrix][rowsOfMatrix]; - for (int i = 0; i < colsOfMatrix; i++) { - for (int j = 0; j < rowsOfMatrix; j++) { - matrix[i][j] = sc.nextInt(); + for (int x = 0; x < colsOfMatrix; x++) { + for (int y = 0; y < rowsOfMatrix; y++) { + matrix[x][y] = sc.nextInt(); } } sc.close(); - int chocolateNum[] = new int[numberOfMoves]; + int chocolateCounts[] = new int[numberOfMoves]; // 1文字ずつ条件にあったメソッドを動かす for (int i = 0; i < numberOfMoves; i++) { - switch (array[i]) { + switch (arrayOfChar[i]) { case 'F': - potion.moveFront(); + position.moveFront(); break; case 'B': - potion.moveBack(); + position.moveBack(); break; case 'L': - potion.moveLeft(); + position.moveLeft(); break; case 'R': - potion.moveRight(); + position.moveRight(); break; } // チョコの個数を記述 - chocolateNum[i] = matrix[potion.getCols()][potion.getRows()]; + chocolateCounts[i] = matrix[position.getCols()][position.getRows()]; } // 出力 - for (int num : chocolateNum) { + for (int num : chocolateCounts) { System.out.println(num); } } -- GitLab From 07396b77260cbfb831e4d8d87fe20c6341ccca5d Mon Sep 17 00:00:00 2001 From: anakamura Date: Tue, 8 Jul 2025 17:17:54 +0900 Subject: [PATCH 3/4] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB136?= =?UTF-8?q?=E3=81=AE=E8=AA=B2=E9=A1=8C=E3=81=AE=E4=BF=AE=E6=AD=A32?= =?UTF-8?q?=E5=9B=9E=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anakamura/src/B136.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/anakamura/src/B136.java b/anakamura/src/B136.java index 9cbae7b..b7a77ad 100644 --- a/anakamura/src/B136.java +++ b/anakamura/src/B136.java @@ -17,10 +17,10 @@ public class B136 { final String movedRoute = sc.next();// 移動経路 // 文字列を1文字ずつに分割する - char[] arrayOfChar = new char[movedRoute.length()]; + char[] RouteChars = new char[movedRoute.length()]; for (int i = 0; i < movedRoute.length(); i++) { char movement = (movedRoute.charAt(i)); - arrayOfChar[i] = movement; + RouteChars[i] = movement; } Position position = new Position(startRows, startCols); @@ -36,7 +36,7 @@ public class B136 { int chocolateCounts[] = new int[numberOfMoves]; // 1文字ずつ条件にあったメソッドを動かす for (int i = 0; i < numberOfMoves; i++) { - switch (arrayOfChar[i]) { + switch (RouteChars[i]) { case 'F': position.moveFront(); break; -- GitLab From 29982d553b83b2ecadc8a5795e83a1dcc86f7468 Mon Sep 17 00:00:00 2001 From: anakamura Date: Tue, 8 Jul 2025 17:27:52 +0900 Subject: [PATCH 4/4] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB136?= =?UTF-8?q?=E3=81=AE=E8=AA=B2=E9=A1=8C=E3=81=AE=E4=BF=AE=E6=AD=A33?= =?UTF-8?q?=E5=9B=9E=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anakamura/src/B136.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/anakamura/src/B136.java b/anakamura/src/B136.java index b7a77ad..584350d 100644 --- a/anakamura/src/B136.java +++ b/anakamura/src/B136.java @@ -17,10 +17,10 @@ public class B136 { final String movedRoute = sc.next();// 移動経路 // 文字列を1文字ずつに分割する - char[] RouteChars = new char[movedRoute.length()]; + char[] routeChars = new char[movedRoute.length()]; for (int i = 0; i < movedRoute.length(); i++) { char movement = (movedRoute.charAt(i)); - RouteChars[i] = movement; + routeChars[i] = movement; } Position position = new Position(startRows, startCols); @@ -36,7 +36,7 @@ public class B136 { int chocolateCounts[] = new int[numberOfMoves]; // 1文字ずつ条件にあったメソッドを動かす for (int i = 0; i < numberOfMoves; i++) { - switch (RouteChars[i]) { + switch (routeChars[i]) { case 'F': position.moveFront(); break; -- GitLab