From 4334337af99a611d9c0852eb4155fc4409f746a2 Mon Sep 17 00:00:00 2001 From: htabuchi Date: Tue, 1 Jul 2025 16:43:21 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E2=80=9Cpainza=E3=81=AE=E5=95=8F=E9=A1=8CB?= =?UTF-8?q?136=E3=81=AE=E5=9B=9E=E7=AD=94=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/.gitkeep | 0 bin/B108_FerrisWheel$FerrisWheel.class | Bin 0 -> 2249 bytes bin/B108_FerrisWheel.class | Bin 0 -> 1627 bytes bin/B108_FerrisWheelTest.class | Bin 0 -> 1065 bytes bin/B108_kanransya$Kanransya.class | Bin 0 -> 1297 bytes bin/B108_kanransya.class | Bin 0 -> 1141 bytes bin/B108_kanransyaTest.class | Bin 0 -> 970 bytes htabuchi/src/B136_htabuchi.java | 148 +++++++++++++++++++++++++ 8 files changed, 148 insertions(+) create mode 100644 bin/.gitkeep create mode 100644 bin/B108_FerrisWheel$FerrisWheel.class create mode 100644 bin/B108_FerrisWheel.class create mode 100644 bin/B108_FerrisWheelTest.class create mode 100644 bin/B108_kanransya$Kanransya.class create mode 100644 bin/B108_kanransya.class create mode 100644 bin/B108_kanransyaTest.class create mode 100644 htabuchi/src/B136_htabuchi.java diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bin/B108_FerrisWheel$FerrisWheel.class b/bin/B108_FerrisWheel$FerrisWheel.class new file mode 100644 index 0000000000000000000000000000000000000000..036bb413fb46b273d408453a8c32f56e64cc1e75 GIT binary patch literal 2249 zcmaJ@TT@$A6#jM+a!NRDX%Jcp^rBFbP$1RXTLP7fg=m@}q0o!k9+D$HH9cWYPUE{5(a7%+npm*|A^xVx$rsG(}rQ4>N@2^{H@CmfvG42_odBa{AO)uXuv#vm3CY_p2 zCnr)@E(?f+z@C};^p!bf?q4a`xkBEUGFFYO<*qS6Qbj1aR(>>T72TLXYsOl!4Y%Z& z0s~FQ@rtbyCT!PSF`d{r@9fVOO13*^6pNIoihuoc{5eIE8ur;TgCpU zKrq={76bU>mTkG?0%t=zj}wU|7_nwMyeNZVV&QsBsrPSxv^O%)aq zHwIW+-3qcd;~Lr5FB_{WsD=v^W3w=rf5mjCnza=SRY|Cq?ck2h-5X1eSW&j7RY~4+ zIwmklqL@w+)xdI(v~C}k9AxF(`u{oM&AApsc<3!nL^3QnwKo8jn3wFjY#nc=n304 zovFP18c-%}bssGzT(eZT1R_pWdL5$SFzBl@Ar^faF%XybE`=uZ$&h$zC$7(qAX z(2tW`4dWc&6Bxw|qIibh~i4 zYV)*0tXCYWhy^P+#2v}(o6IRu{^pH)$2RbzcYFiiFi^Dj5iWZ0B?cZ~igsU5o&7#? zGFOj!)a^I>-BSF|c(KHjXs>$wk9%(0eFLXeZ1rfo(EzNLz&Czh2nneBJ+ye^eeZ6L z-S-HYvS)pBSoYhiSeYb=zy)#?r=rH$nTu5BBuSjYtC+^y{5ZVBo_)bD!BzlvVY6&U~SJ}a9=)_e{;|+zaqOIfG*p4Vf iLgC;)C6Cb}g3NY<**tg|ukan990bmj0^p|FKmRY?Jo%gQ|YpRvD(^EQ3Me&5kgpC zG;ceq&}mkc`@pI;l)%}1t7bLImTPOiCp7$B+ta$ixLNvaTDBuFp86tx62IiTwo}ih z%Mxb<&U6(W-)>||HOq078^IV766a1OUE1?})ig1V*8~FEY2wJG-OA*gcE_hzWi_)= z#F5khUKf~1z0xFI)<#n%rZFQR9rd-Jb65|SAt&*Mz}QJj%dTtfr!Bf(EZi;TmkV1P0wPE7>-URWn_YIO zX0@%F?eB4_`Yv}NF?QW;b=tgSvjI-0NvbLkdw8-$0y8gFr@!V5KYn^U_S(lAGCL4( z@rduAp6n7G43~VX_ISf;cQ;F7g^)_Ej$2b}wqC!)VAHSa2@)`KdTqK5RjgdBZxqNC zl;>|Ky~Q3baDak*D}VqgZaGg$F2k?jH#B#Eq2IddC{L}X5HX%+k2Wz(E`kw^Qo_q( zpXU%|zZ@c7`5k8uFp zutl-ujs@ zf-cNAyif30#tOeN{D4*5WohF04j*BSl}_L()=33<>sx$G?*=2f_=HplbM*5mwP8jd zMxK=9c`Vy{A@ebd4RT>-F-jyw+HEr8I3pbSz4yZJJ^H;*-6V|X1STa)5^*6U()_Wh biCBW^JfKN{Aj|yfw?&V^HtEm!H#Gl0s=;RF literal 0 HcmV?d00001 diff --git a/bin/B108_FerrisWheelTest.class b/bin/B108_FerrisWheelTest.class new file mode 100644 index 0000000000000000000000000000000000000000..41cab925f1dc2eb744bc1ce7e20ca144a5b5b238 GIT binary patch literal 1065 zcmbV~&rcIU6vw|)YD<^$Lj;r`;-aX9gJ|Nx2$Beqgrw0#5W~rA%LImOXUXoC`*!2O zh!;pCsL>EiP)JY?h6q^i{u^V_oBx6FZ6Sb#6Ni1X@6CIk`Ocg7LWH3@DI~w2&7`i9=t^9fA&HUM(Ro;8$trfeb4Ov+`%?CvA7>&oNx)z+t z5FeD1+x@2DINXWiDnm5YCXTDssxHt^(CWsH0eXw+8iSAdlfJ@j^I9{}J*UX${yn z_t@GNnnr6|HqiQ=qPx@}FJK?gw0&CJ32BYT(k`Bm)_x2vgiFO6wBs_ZK@YFc9TLDl D{5TMN literal 0 HcmV?d00001 diff --git a/bin/B108_kanransya$Kanransya.class b/bin/B108_kanransya$Kanransya.class new file mode 100644 index 0000000000000000000000000000000000000000..cd75af1ace107e60421ae99f533c8a1cbe452f2d GIT binary patch literal 1297 zcmZ`(+fEZv6kTVgrL>M*iXgUtqNrumR=lDVyfhlCTntrA#6*TN*1ub6QZ0ra80sIcHziTKlA5et!H6U>x}vG=bjBBgaSYKeAlk za)UK%=*FfOLqwos*?Mf{s+L>H%`7h4pta(Awbkj`ia<-=ah-5NAf71}=lL6+6NnVNB|8Bf9R>_^3h0^P zxi|#63`Ef)y>0`shPT^5E8_BOkAXzPOB>jMI9pFTuFXD+wtvf7tl9#}Nv~{G=Pcim z`{rRJeCQBXYVv>V$Cy~L!@}Q0BAH>yu#F|le-aeSRKy`ECzy4X>`T=u_jd($mO`ui zXv$h`Htq@@dQbkU8i$FaF&x<@cWEsM?G*#Zkfj=4jmmdVs%bc0?xyd!VJY-&Yh^5f z<2Vt+2(|jhwSkj3B@kPc8C91`XO!THl2`M~_Ekqp)U{oOtgIto6kXT$3spJBAck{f zy*-X>w_XcJJZ%TzH7^LUkCV~)#G=sT@aSoBbjosY%5rSVa%i*>E(1H6*GBJ|$^!gX}kpAvQSntLL3q~53!ef$ov0TWngKMNjUnIUxHAW}F)IET^C z+fxK1V+OF7R(cYgP@aURDNh2F;0NVOM;WODr)<`b+5|xhjFNsU>C5xcU!tDm>;M1& literal 0 HcmV?d00001 diff --git a/bin/B108_kanransya.class b/bin/B108_kanransya.class new file mode 100644 index 0000000000000000000000000000000000000000..87da1c1f6a54e8e3df57cddbab94a6435a4202dc GIT binary patch literal 1141 zcmZuvT~8B16g@+?yYvGnlp=*<1wjia1(gpeMFm6BSc*waBSA64x+x3omh5g--u)v! z`K%9+i17#bZ~O!589+V^Y4_fld*yR&bE6dlodTW5K-0Ht z*|I4e$8tl6BVnNX66Nx~=UeqCdT>pkMHNk)l(ZY!g0t83S=EyDTo^GV75zSe-prLp zMl0%2DvAMI7cd;_gI{o{21O_sxWT;3eGEVQr(+mt45{Kb1wxrZVS_(aEsc>VZYjmu zsgC(vdYrj7M=t;X$+3@F=k+-73|LUm+Pmj~Wp? zY3!nER9lqz75J?Rw3>2Hnzp}BwKfjt)kcES~b5DpEf}Z2c>`4$)g2 zKR|z8nZ?xi@Vqua6AaAgpV5)j61oD`KI$T&r#}7pbs7&|j1Mq=g!Fo9AgLvThZvmK zlllRMmATFIF-0-}MRJM5Mdl=FaMg+g$@LLQlj;b`PSDR1$)gi1^lRwGCg<8jFSe0H zji*(Eub9UsaF-ciWQ(dyvc(u)V+!}ESOPC`pQ`{f%6NcjXuPF_8LomDB0fu0$Nbr9 zlOoOG;c*P;hxUh*3z#jNZ1v`UV0^n2N|h6beLHVv-sipdowxaCy$S$VpmLw!@KE$F#_QsbAqbS1_$GyK$Jj7mT`KgSjbUpRL>a{^JmSxZj9*`^ZmwV*m=xs z0$u;4@{7YHiQ2Odwb_LqU*@D+mf~G~-X)N_SL6;W&|zL;Hbc~P&P_*mn8}e8$p*0s zbYTt6&Td+kX+_~Ef%1KBQQI_1bVAFUg=uC4q1v=%BCB9u*3_7f(4;$4d;3C) z`s%tA6)9dyQI+DgbZ6C=^cJN1O?sa6o@>lbGwwVbAJC-ugkf5%bX!1CslQpOt-ShK z{TR^ZRTVm+$5-qafn++{tarq*7@r*UrA@Vpup|W*wYZ~(bU#aPS$Z4No0Fpadt*k5 z_fo6`TB##u(aO_X%zuFH|7$wuXCx3G=A2qXhHl%`RzM@r(|Wi0^a`9N(B67VAht6a z&<8jZICccT0}w$Q#x>3a+8BBn{0C=e*FasxjS$4qMz%KL5U%5mbvtyRhZBmyAvn^w zmB7Cbx`=6fkopxmA0(1%(ES~~-86L=eCJ!z?Z(zHEjAvhj%Z~{*HePMT} JP|h_B3 literal 0 HcmV?d00001 diff --git a/htabuchi/src/B136_htabuchi.java b/htabuchi/src/B136_htabuchi.java new file mode 100644 index 0000000..132d3bd --- /dev/null +++ b/htabuchi/src/B136_htabuchi.java @@ -0,0 +1,148 @@ +/** + * Paiza問題B136:チョコのお返し
+ * create 2025/7/1 + * + * @author 田渕日奈子 + * @version 1.0 + */ + +import java.util.Scanner; + +public class B136_htabuchi { + private int movedTimes; /** 経路回数 */ + private int curLocateX; /** 現在の座標X */ + private int curLocateY; /** 現在の座標Y */ + private String route; /** 移動経路 */ + private int[][] routeMatrix; /** 経路行列 */ + + public B136_htabuchi() { + + } + + public B136_htabuchi(int times, int height, int width, int curLocateX, int curLocateY, + String route) { + this.movedTimes = times; + this.curLocateX = curLocateX - 1; + this.curLocateY = curLocateY - 1;; + this.route = route; + this.routeMatrix = new int[height][width]; + } + + /** scan処理から必要な移動値や行列を作る関数 */ + public static B136_htabuchi scanningRequiredValue() { + + Scanner sc = new Scanner(System.in); + int movedTimes = sc.nextInt(); /** 経路回数 */ + int matrixHeight = sc.nextInt(); /** 座席配列の行 */ + int matrixWidth = sc.nextInt(); /** 座席配列の列 */ + int curLocateX = sc.nextInt(); /** 現在の座標X */ + int curLocateY = sc.nextInt(); /** 現在の座標Y */ + String route = sc.next(); /** 移動経路 */ + B136_htabuchi b136Inst = new B136_htabuchi(movedTimes, matrixHeight, matrixWidth, curLocateX, + curLocateY, route); + + for (int i = 0; i < matrixHeight; i++) { + for (int j = 0; j < matrixWidth; j++) { + int matrixValue = sc.nextInt(); + b136Inst.setRouteMatrix(i, j, matrixValue); + } + } + + sc.close(); + return b136Inst; + } + + public char[] decomposeString() { + /** 移動経路順を格納する */ + String routeString = this.getRoute(); + char[] charArray = routeString.toCharArray(); + return charArray; + } + + public void displayReceiveChocolate(char[] routeMessage) { + for (char route : routeMessage) { + switch (route) { + case 'F': + /** 正面から見て上移動 */ + this.setCurLocateX(this.getCurLocateX() - 1); + this.displayChocolateNum(); + break; + case 'B': + /** 正面から見て下移動 */ + this.setCurLocateX(getCurLocateX() + 1); + this.displayChocolateNum(); + break; + case 'L': + /** 正面から見て左移動 */ + this.setCurLocateY(getCurLocateY() - 1); + this.displayChocolateNum(); + break; + case 'R': + /** 正面から見て右移動 */ + this.setCurLocateY(getCurLocateY() + 1); + this.displayChocolateNum(); + break; + default: + break; + } + } + } + + public void displayChocolateNum() { + int chocolate = 0; + chocolate = this.getRouteMatrix(this.getCurLocateX(), this.getCurLocateY()); + System.out.println(chocolate); + } + + /** メイン関数 */ + public static void main(String[] args) { + B136_htabuchi b136Inst = new B136_htabuchi(); + /** スキャン情報から移動経路を読む */ + /** チョコの数を経路に順に表示する */ + b136Inst = scanningRequiredValue(); + char[] routeMesage = b136Inst.decomposeString(); + b136Inst.displayReceiveChocolate(routeMesage); + } + + /** 以下セッターとゲッター */ + public int getRouteMatrix(int height, int width) { + return this.routeMatrix[height][width]; + } + + public int[][] getRouteMatrix() { + return this.routeMatrix; + } + + public void setRouteMatrix(int height, int width, int matrixValue) { + this.routeMatrix[height][width] = matrixValue; + } + + public void setRouteMatrix(int[][] routeMatrix) { + this.routeMatrix = routeMatrix; + } + + public String getRoute() { + return this.route; + } + + public String getRouteMatrix(String route) { + return this.route = route; + } + + public int getCurLocateX() { + return curLocateX; + } + + public void setCurLocateX(int curLocateX) { + this.curLocateX = curLocateX; + } + + public int getCurLocateY() { + return curLocateY; + } + + public void setCurLocateY(int curLocateY) { + this.curLocateY = curLocateY; + } + +} -- GitLab From 4ec8158ceccd962b2fe6313485f47177f0fffffd Mon Sep 17 00:00:00 2001 From: htabuchi Date: Wed, 2 Jul 2025 14:43:12 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E2=80=9Cpaiza=E3=81=AE=E5=95=8F=E9=A1=8CB1?= =?UTF-8?q?36=E3=81=AE=E5=9B=9E=E7=AD=94=E3=82=92=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htabuchi/src/B136_htabuchi.java | 200 +++++++++++++++++++------------- 1 file changed, 118 insertions(+), 82 deletions(-) diff --git a/htabuchi/src/B136_htabuchi.java b/htabuchi/src/B136_htabuchi.java index 132d3bd..94b589b 100644 --- a/htabuchi/src/B136_htabuchi.java +++ b/htabuchi/src/B136_htabuchi.java @@ -9,140 +9,176 @@ import java.util.Scanner; public class B136_htabuchi { - private int movedTimes; /** 経路回数 */ - private int curLocateX; /** 現在の座標X */ - private int curLocateY; /** 現在の座標Y */ - private String route; /** 移動経路 */ - private int[][] routeMatrix; /** 経路行列 */ - public B136_htabuchi() { + private static class Dto { + private int movedTimes; + /** 経路回数 */ + private int curLocateX; + /** 現在の座標X */ + private int curLocateY; + /** 現在の座標Y */ + private String route; + /** 移動経路 */ + private int[][] routeMatrix; + + /** 経路行列 */ + + public Dto(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 void setRouteMatrix(int[][] routeMatrix) { + this.routeMatrix = routeMatrix; + } + + /** 経路 */ + public String getRoute() { + return this.route; + } + + public String getRoute(String route) { + return this.route = route; + } + + /** スタート地点の座標 */ + public int getCurLocateX() { + return curLocateX; + } + + public void setCurLocateX(int curLocateX) { + this.curLocateX = curLocateX; + } + + public int getCurLocateY() { + return curLocateY; + } + + public void setCurLocateY(int curLocateY) { + this.curLocateY = curLocateY; + } - public B136_htabuchi(int times, int height, int width, int curLocateX, int curLocateY, - String route) { - this.movedTimes = times; - this.curLocateX = curLocateX - 1; - this.curLocateY = curLocateY - 1;; - this.route = route; - this.routeMatrix = new int[height][width]; } /** scan処理から必要な移動値や行列を作る関数 */ - public static B136_htabuchi scanningRequiredValue() { + public static Dto scanningRequiredValue() { Scanner sc = new Scanner(System.in); - int movedTimes = sc.nextInt(); /** 経路回数 */ - int matrixHeight = sc.nextInt(); /** 座席配列の行 */ - int matrixWidth = sc.nextInt(); /** 座席配列の列 */ - int curLocateX = sc.nextInt(); /** 現在の座標X */ - int curLocateY = sc.nextInt(); /** 現在の座標Y */ - String route = sc.next(); /** 移動経路 */ - B136_htabuchi b136Inst = new B136_htabuchi(movedTimes, matrixHeight, matrixWidth, curLocateX, - curLocateY, route); + int movedTimes = sc.nextInt(); /** 経路回数 */ + int matrixHeight = sc.nextInt();/** 座席配列の行 */ + int matrixWidth = sc.nextInt(); /** 座席配列の列 */ + int curLocateX = sc.nextInt(); /** 現在の座標X */ + int curLocateY = sc.nextInt(); /** 現在の座標Y */ + String route = sc.next(); /** 移動経路 */ + Dto dto = new Dto(movedTimes, matrixHeight, matrixWidth, curLocateX, curLocateY, route); for (int i = 0; i < matrixHeight; i++) { for (int j = 0; j < matrixWidth; j++) { int matrixValue = sc.nextInt(); - b136Inst.setRouteMatrix(i, j, matrixValue); + dto.setRouteMatrix(i, j, matrixValue); } } sc.close(); - return b136Inst; + return dto; } - public char[] decomposeString() { + public static char[] decomposeString(Dto dto) { /** 移動経路順を格納する */ - String routeString = this.getRoute(); + String routeString = dto.getRoute(); char[] charArray = routeString.toCharArray(); return charArray; } - public void displayReceiveChocolate(char[] routeMessage) { - for (char route : routeMessage) { - switch (route) { + public static int[] displayReceiveChocolate(Dto dto, char[] routeMessage) { + int[] chocoArray = new int[dto.getMovedTimes()]; + for (int i = 0; i < dto.getMovedTimes(); i++) { + switch (routeMessage[i]) { case 'F': /** 正面から見て上移動 */ - this.setCurLocateX(this.getCurLocateX() - 1); - this.displayChocolateNum(); + chocoArray[i] = moveFront(dto, chocoArray[i]); break; case 'B': /** 正面から見て下移動 */ - this.setCurLocateX(getCurLocateX() + 1); - this.displayChocolateNum(); + chocoArray[i] = moveBack(dto, chocoArray[i]); break; case 'L': /** 正面から見て左移動 */ - this.setCurLocateY(getCurLocateY() - 1); - this.displayChocolateNum(); + chocoArray[i] = moveLeft(dto, chocoArray[i]); break; case 'R': /** 正面から見て右移動 */ - this.setCurLocateY(getCurLocateY() + 1); - this.displayChocolateNum(); + chocoArray[i] = moveRight(dto, chocoArray[i]); break; default: break; } } - } - - public void displayChocolateNum() { - int chocolate = 0; - chocolate = this.getRouteMatrix(this.getCurLocateX(), this.getCurLocateY()); - System.out.println(chocolate); - } - - /** メイン関数 */ - public static void main(String[] args) { - B136_htabuchi b136Inst = new B136_htabuchi(); - /** スキャン情報から移動経路を読む */ - /** チョコの数を経路に順に表示する */ - b136Inst = scanningRequiredValue(); - char[] routeMesage = b136Inst.decomposeString(); - b136Inst.displayReceiveChocolate(routeMesage); - } - /** 以下セッターとゲッター */ - public int getRouteMatrix(int height, int width) { - return this.routeMatrix[height][width]; + /** 経路上のチョコ配列 */ + return chocoArray; } - public int[][] getRouteMatrix() { - return this.routeMatrix; + public static int moveFront(Dto dto, int chocoArray) { + dto.setCurLocateX(dto.getCurLocateX() - 1); + chocoArray = dto.getRouteMatrix(dto.getCurLocateX(), dto.getCurLocateY()); + return chocoArray; } - public void setRouteMatrix(int height, int width, int matrixValue) { - this.routeMatrix[height][width] = matrixValue; + public static int moveBack(Dto dto, int chocoArray) { + dto.setCurLocateX(dto.getCurLocateX() + 1); + chocoArray = dto.getRouteMatrix(dto.getCurLocateX(), dto.getCurLocateY()); + return chocoArray; } - public void setRouteMatrix(int[][] routeMatrix) { - this.routeMatrix = routeMatrix; + public static int moveLeft(Dto dto, int chocoArray) { + dto.setCurLocateY(dto.getCurLocateY() - 1); + chocoArray = dto.getRouteMatrix(dto.getCurLocateX(), dto.getCurLocateY()); + return chocoArray; } - public String getRoute() { - return this.route; + public static int moveRight(Dto dto, int chocoArray) { + dto.setCurLocateY(dto.getCurLocateY() + 1); + chocoArray = dto.getRouteMatrix(dto.getCurLocateX(), dto.getCurLocateY()); + return chocoArray; } - public String getRouteMatrix(String route) { - return this.route = route; - } - - public int getCurLocateX() { - return curLocateX; - } - - public void setCurLocateX(int curLocateX) { - this.curLocateX = curLocateX; - } - - public int getCurLocateY() { - return curLocateY; + public static void displayChocolateNum(int[] chocoArray) { + for (int i : chocoArray) { + System.out.println(i); + } } - public void setCurLocateY(int curLocateY) { - this.curLocateY = curLocateY; + /** メイン関数 */ + public static void main(String[] args) { + /** スキャン情報から移動経路を読む */ + /** チョコの数を経路に順に表示する */ + Dto dto = scanningRequiredValue(); + char[] routeMesage = decomposeString(dto); + int[] chocoArray = displayReceiveChocolate(dto, routeMesage); + displayChocolateNum(chocoArray); } } -- GitLab From 4b6f3b4f34081c9709a0e9c4ff8882c1cfc71bfb Mon Sep 17 00:00:00 2001 From: htabuchi Date: Thu, 3 Jul 2025 13:52:49 +0900 Subject: [PATCH 3/3] =?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=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htabuchi/src/B136_htabuchi.java | 95 +++++++++++++-------------------- 1 file changed, 36 insertions(+), 59 deletions(-) diff --git a/htabuchi/src/B136_htabuchi.java b/htabuchi/src/B136_htabuchi.java index 94b589b..f144465 100644 --- a/htabuchi/src/B136_htabuchi.java +++ b/htabuchi/src/B136_htabuchi.java @@ -10,7 +10,7 @@ import java.util.Scanner; public class B136_htabuchi { - private static class Dto { + private class RouteInfoData { private int movedTimes; /** 経路回数 */ private int curLocateX; @@ -23,11 +23,11 @@ public class B136_htabuchi { /** 経路行列 */ - public Dto(final int times, final int height, final int width, final int curLocateX, + 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.curLocateY = curLocateY - 1; this.route = route; this.routeMatrix = new int[height][width]; } @@ -50,11 +50,6 @@ public class B136_htabuchi { return this.routeMatrix; } - public void setRouteMatrix(int[][] routeMatrix) { - this.routeMatrix = routeMatrix; - } - - /** 経路 */ public String getRoute() { return this.route; } @@ -63,36 +58,41 @@ public class B136_htabuchi { return this.route = route; } - /** スタート地点の座標 */ - public int getCurLocateX() { - return curLocateX; + /** 上下左右移動 */ + public int moveFront() { + this.curLocateX = curLocateX - 1; + return getRouteMatrix(curLocateX, curLocateY); } - public void setCurLocateX(int curLocateX) { - this.curLocateX = curLocateX; + public int moveBack() { + this.curLocateX = curLocateX + 1; + return getRouteMatrix(curLocateX, curLocateY); } - public int getCurLocateY() { - return curLocateY; + public int moveLeft() { + this.curLocateY = curLocateY - 1; + return getRouteMatrix(curLocateX, curLocateY); } - public void setCurLocateY(int curLocateY) { - this.curLocateY = curLocateY; + public int moveRight() { + this.curLocateY = curLocateY + 1; + return getRouteMatrix(curLocateX, curLocateY); } } /** scan処理から必要な移動値や行列を作る関数 */ - public static Dto scanningRequiredValue() { + public RouteInfoData scanningRequiredValue() { Scanner sc = new Scanner(System.in); - int movedTimes = sc.nextInt(); /** 経路回数 */ - int matrixHeight = sc.nextInt();/** 座席配列の行 */ - int matrixWidth = sc.nextInt(); /** 座席配列の列 */ - int curLocateX = sc.nextInt(); /** 現在の座標X */ - int curLocateY = sc.nextInt(); /** 現在の座標Y */ - String route = sc.next(); /** 移動経路 */ - Dto dto = new Dto(movedTimes, matrixHeight, matrixWidth, curLocateX, curLocateY, route); + 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++) { @@ -105,32 +105,32 @@ public class B136_htabuchi { return dto; } - public static char[] decomposeString(Dto dto) { + public static char[] decomposeString(RouteInfoData dto) { /** 移動経路順を格納する */ String routeString = dto.getRoute(); - char[] charArray = routeString.toCharArray(); + final char[] charArray = routeString.toCharArray(); return charArray; } - public static int[] displayReceiveChocolate(Dto dto, char[] routeMessage) { + 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] = moveFront(dto, chocoArray[i]); + chocoArray[i] = dto.moveFront(); break; case 'B': /** 正面から見て下移動 */ - chocoArray[i] = moveBack(dto, chocoArray[i]); + chocoArray[i] = dto.moveBack(); break; case 'L': /** 正面から見て左移動 */ - chocoArray[i] = moveLeft(dto, chocoArray[i]); + chocoArray[i] = dto.moveLeft(); break; case 'R': /** 正面から見て右移動 */ - chocoArray[i] = moveRight(dto, chocoArray[i]); + chocoArray[i] = dto.moveRight(); break; default: break; @@ -141,30 +141,6 @@ public class B136_htabuchi { return chocoArray; } - public static int moveFront(Dto dto, int chocoArray) { - dto.setCurLocateX(dto.getCurLocateX() - 1); - chocoArray = dto.getRouteMatrix(dto.getCurLocateX(), dto.getCurLocateY()); - return chocoArray; - } - - public static int moveBack(Dto dto, int chocoArray) { - dto.setCurLocateX(dto.getCurLocateX() + 1); - chocoArray = dto.getRouteMatrix(dto.getCurLocateX(), dto.getCurLocateY()); - return chocoArray; - } - - public static int moveLeft(Dto dto, int chocoArray) { - dto.setCurLocateY(dto.getCurLocateY() - 1); - chocoArray = dto.getRouteMatrix(dto.getCurLocateX(), dto.getCurLocateY()); - return chocoArray; - } - - public static int moveRight(Dto dto, int chocoArray) { - dto.setCurLocateY(dto.getCurLocateY() + 1); - chocoArray = dto.getRouteMatrix(dto.getCurLocateX(), dto.getCurLocateY()); - return chocoArray; - } - public static void displayChocolateNum(int[] chocoArray) { for (int i : chocoArray) { System.out.println(i); @@ -173,11 +149,12 @@ public class B136_htabuchi { /** メイン関数 */ public static void main(String[] args) { + B136_htabuchi program = new B136_htabuchi(); /** スキャン情報から移動経路を読む */ /** チョコの数を経路に順に表示する */ - Dto dto = scanningRequiredValue(); - char[] routeMesage = decomposeString(dto); - int[] chocoArray = displayReceiveChocolate(dto, routeMesage); + RouteInfoData dto = program.scanningRequiredValue(); + final char[] routeMesage = decomposeString(dto); + final int[] chocoArray = displayReceiveChocolate(dto, routeMesage); displayChocolateNum(chocoArray); } -- GitLab