From 07f180258f1146a8ffc11fc26f1b887be9c2e68b Mon Sep 17 00:00:00 2001 From: anakamura Date: Mon, 7 Jul 2025 14:46:37 +0900 Subject: [PATCH] =?UTF-8?q?paiza=E3=81=AEmonndai?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- anakamura/src/C114.java | 32 +++++++------------ anakamura_2/Main.java | 69 +++++++++++++++++++++++++++++++++++++++++ anakamura_2/Sub.java | 28 +++++++++++++++++ 3 files changed, 108 insertions(+), 21 deletions(-) create mode 100644 anakamura_2/Main.java create mode 100644 anakamura_2/Sub.java diff --git a/anakamura/src/C114.java b/anakamura/src/C114.java index f5e4fa7..271cfea 100644 --- a/anakamura/src/C114.java +++ b/anakamura/src/C114.java @@ -12,46 +12,36 @@ public class C114 { final int N = sc.nextInt(); sc.nextLine(); // Listを作成し、すべての文字列を取得 - List words = new ArrayList<>(); + final List words = new ArrayList<>(); for (int i = 0; i < N; i++) { words.add(sc.nextLine()); } sc.close(); - C114 checkKeywords = new C114(); - checkKeywords.wordsCheckMethod(words); + System.out.println(wordsCheckMethod(words)); + } - public void wordsCheckMethod(List words) { + public static String wordsCheckMethod(final List words) { + // 初めの単語の末尾と次の単語の先頭の文字が等しいかを順番に調べる - for (int i = 0; i < words.size(); i++) { + for (int i = 0; i + 1 > words.size(); i++) { final String currentword = words.get(i); // 初めの単語の末尾を取得 final char char1 = (currentword.charAt(currentword.length() - 1)); - /* - * wordの配列 しりとりがうまく進み、 どちらかを満たしていれば、しりとりが終了 「Yes」を返す - */ - if (i + 1 >= words.size() || words.get(i + 1).isEmpty()) { - System.out.println("Yes"); - break; - } // 次の単語の先頭の文字を取得 final char char2 = (words.get(i + 1).charAt(0)); - // char1とchar2が等しいかを調べる - if (char1 == char2) { - // しりとりが続く場合 - continue; - // しりとりが続かなかったときの文字を出力 - } else { + // char1とchar2が等しくない場合、こちらを出力 + if (char1 != char2) { final StringBuilder sb = new StringBuilder(); sb.append(char1).append(" ").append(char2); final String result = sb.toString(); - System.out.println(result); - break; + return sb.toString(); } - } + } // すべて等しいときは、こちらを出力 + return "Yes"; } } diff --git a/anakamura_2/Main.java b/anakamura_2/Main.java new file mode 100644 index 0000000..7c57b42 --- /dev/null +++ b/anakamura_2/Main.java @@ -0,0 +1,69 @@ +package anakamura_2; + +import java.util.Scanner; + +public class Main { + /* + * private int numberOfMoves; //移動回数 private int rowsOfMatrix; // 縦の列の数 private int colsOfMatrix; + * //横の列の数 private int rows; //自分の行 private int cols; //自分の列 array[] char array; + */ + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + final int numberOfMoves = sc.nextInt(); // 移動回数 + final int rowsOfMatrix = sc.nextInt(); // 縦の列の数 + final int colsOfMatrix = sc.nextInt(); // 横の列の数 + + final int rows = sc.nextInt(); // 自分の行 + final int cols = sc.nextInt();// 自分の列 + + final String movedRoute = sc.next();// 移動経路 + + char[] array = new char[movedRoute.length()]; + for (int i = 0; i < movedRoute.length(); i++) { + char movement = (movedRoute.charAt(i)); + array[i] = movement; + } + Sub sub = new Sub(); + // movedRoute.length()==numberOfMoves;//文字列の長さは移動回数の長さと同じ! + + /* + * i 行目の j 番目 (1 ≦ j ≦ W) の整数 c_{i, j} は前から i 列目、 から j 列目に座っているクラスメイトがくれるチョコレートの数を表す。 + */ + final int[][] matrix = new int[rowsOfMatrix][colsOfMatrix]; + for (int i = 0; i < rows; i++) { + for (int j = 0; j < rows; j++) { + matrix[i][j] = sc.nextInt(); + } + } + sc.close(); + + int choco[] = new int[movedRoute.length()]; + + for (int i = 0; i < array.length; i++) { + switch (array[i]) { + case 'F': + sub.moveF(rows, cols); + + break; + case 'B': + sub.moveB(rows, cols); + break; + case 'L': + sub.moveL(rows, cols); + break; + case 'R': + sub.moveR(rows, cols); + break; + } + choco[i] = matrix[sub.getrows()][sub.getcols()]; + } + for (int num : choco) { + System.out.println(num); + } + // 移動方向 + // public void + } +} diff --git a/anakamura_2/Sub.java b/anakamura_2/Sub.java new file mode 100644 index 0000000..008a427 --- /dev/null +++ b/anakamura_2/Sub.java @@ -0,0 +1,28 @@ +package anakamura_2; + +public class Sub{ + private int rows,cols; + // Sub(int rows, int cols) {} + public int getrows() { + return rows; + } + public int getcols() { + return cols;} + + + public void moveF(int rows,int cols) { + rows +=1; + } + public void moveB(int rows,int cols) { + rows -=1; + } + public void moveL(int rows,int cols) { + cols +=1; + } + public void moveR(int rows,int cols) { + cols -=1; + } + // TODO 自動生成されたメソッド・スタブ + + + } -- GitLab