diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/bin/B108_FerrisWheel$FerrisWheel.class b/bin/B108_FerrisWheel$FerrisWheel.class new file mode 100644 index 0000000000000000000000000000000000000000..036bb413fb46b273d408453a8c32f56e64cc1e75 Binary files /dev/null and b/bin/B108_FerrisWheel$FerrisWheel.class differ diff --git a/bin/B108_FerrisWheel.class b/bin/B108_FerrisWheel.class new file mode 100644 index 0000000000000000000000000000000000000000..9c3a425e02f54e962b81e681a01f9188e6294599 Binary files /dev/null and b/bin/B108_FerrisWheel.class differ diff --git a/bin/B108_FerrisWheelTest.class b/bin/B108_FerrisWheelTest.class new file mode 100644 index 0000000000000000000000000000000000000000..41cab925f1dc2eb744bc1ce7e20ca144a5b5b238 Binary files /dev/null and b/bin/B108_FerrisWheelTest.class differ diff --git a/bin/B108_kanransya$Kanransya.class b/bin/B108_kanransya$Kanransya.class new file mode 100644 index 0000000000000000000000000000000000000000..cd75af1ace107e60421ae99f533c8a1cbe452f2d Binary files /dev/null and b/bin/B108_kanransya$Kanransya.class differ diff --git a/bin/B108_kanransya.class b/bin/B108_kanransya.class new file mode 100644 index 0000000000000000000000000000000000000000..87da1c1f6a54e8e3df57cddbab94a6435a4202dc Binary files /dev/null and b/bin/B108_kanransya.class differ diff --git a/bin/B108_kanransyaTest.class b/bin/B108_kanransyaTest.class new file mode 100644 index 0000000000000000000000000000000000000000..8cc4dbe06c0565b11d07e7e0458053fbe529ae63 Binary files /dev/null and b/bin/B108_kanransyaTest.class differ diff --git a/htabuchi/src/B136_htabuchi.java b/htabuchi/src/B136_htabuchi.java new file mode 100644 index 0000000000000000000000000000000000000000..f144465ecffd5bff33c7e6751e2204f4e2a28b57 --- /dev/null +++ b/htabuchi/src/B136_htabuchi.java @@ -0,0 +1,161 @@ +/** + * Paiza問題B136:チョコのお返し
+ * create 2025/7/1 + * + * @author 田渕日奈子 + * @version 1.0 + */ + +import java.util.Scanner; + +public class B136_htabuchi { + + private class RouteInfoData { + private int movedTimes; + /** 経路回数 */ + private int curLocateX; + /** 現在の座標X */ + private int curLocateY; + /** 現在の座標Y */ + private String route; + /** 移動経路 */ + private int[][] routeMatrix; + + /** 経路行列 */ + + public RouteInfoData(final int times, final int height, final int width, final int curLocateX, + final int curLocateY, final String route) { + this.movedTimes = times; + this.curLocateX = curLocateX - 1; + this.curLocateY = curLocateY - 1; + this.route = route; + this.routeMatrix = new int[height][width]; + } + + /** 以下セッターとゲッター */ + + public int getMovedTimes() { + return this.movedTimes; + } + + public int getRouteMatrix(int height, int width) { + return this.routeMatrix[height][width]; + } + + public void setRouteMatrix(int height, int width, int matrixValue) { + this.routeMatrix[height][width] = matrixValue; + } + + public int[][] getRouteMatrix() { + return this.routeMatrix; + } + + public String getRoute() { + return this.route; + } + + public String getRoute(String route) { + return this.route = route; + } + + /** 上下左右移動 */ + public int moveFront() { + this.curLocateX = curLocateX - 1; + return getRouteMatrix(curLocateX, curLocateY); + } + + public int moveBack() { + this.curLocateX = curLocateX + 1; + return getRouteMatrix(curLocateX, curLocateY); + } + + public int moveLeft() { + this.curLocateY = curLocateY - 1; + return getRouteMatrix(curLocateX, curLocateY); + } + + public int moveRight() { + this.curLocateY = curLocateY + 1; + return getRouteMatrix(curLocateX, curLocateY); + } + + } + + /** scan処理から必要な移動値や行列を作る関数 */ + public RouteInfoData scanningRequiredValue() { + + Scanner sc = new Scanner(System.in); + final int movedTimes = sc.nextInt(); /** 経路回数 */ + final int matrixHeight = sc.nextInt();/** 座席配列の行 */ + final int matrixWidth = sc.nextInt(); /** 座席配列の列 */ + final int curLocateX = sc.nextInt(); /** 現在の座標X */ + final int curLocateY = sc.nextInt(); /** 現在の座標Y */ + final String route = sc.next(); /** 移動経路 */ + RouteInfoData dto = new RouteInfoData(movedTimes, matrixHeight, matrixWidth, curLocateX, + curLocateY, route); + + for (int i = 0; i < matrixHeight; i++) { + for (int j = 0; j < matrixWidth; j++) { + int matrixValue = sc.nextInt(); + dto.setRouteMatrix(i, j, matrixValue); + } + } + + sc.close(); + return dto; + } + + public static char[] decomposeString(RouteInfoData dto) { + /** 移動経路順を格納する */ + String routeString = dto.getRoute(); + final char[] charArray = routeString.toCharArray(); + return charArray; + } + + public static int[] displayReceiveChocolate(RouteInfoData dto, char[] routeMessage) { + int[] chocoArray = new int[dto.getMovedTimes()]; + for (int i = 0; i < dto.getMovedTimes(); i++) { + switch (routeMessage[i]) { + case 'F': + /** 正面から見て上移動 */ + chocoArray[i] = dto.moveFront(); + break; + case 'B': + /** 正面から見て下移動 */ + chocoArray[i] = dto.moveBack(); + break; + case 'L': + /** 正面から見て左移動 */ + chocoArray[i] = dto.moveLeft(); + break; + case 'R': + /** 正面から見て右移動 */ + chocoArray[i] = dto.moveRight(); + break; + default: + break; + } + } + + /** 経路上のチョコ配列 */ + return chocoArray; + } + + public static void displayChocolateNum(int[] chocoArray) { + for (int i : chocoArray) { + System.out.println(i); + } + } + + /** メイン関数 */ + public static void main(String[] args) { + B136_htabuchi program = new B136_htabuchi(); + /** スキャン情報から移動経路を読む */ + /** チョコの数を経路に順に表示する */ + RouteInfoData dto = program.scanningRequiredValue(); + final char[] routeMesage = decomposeString(dto); + final int[] chocoArray = displayReceiveChocolate(dto, routeMesage); + displayChocolateNum(chocoArray); + } + +}