From 9c155a171b3fb7074c15827596354650fec2a99d Mon Sep 17 00:00:00 2001 From: anakamura Date: Fri, 4 Jul 2025 13:11:05 +0900 Subject: [PATCH 1/3] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CC114?= =?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/C114.java | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 anakamura/src/C114.java diff --git a/anakamura/src/C114.java b/anakamura/src/C114.java new file mode 100644 index 0000000..f5e4fa7 --- /dev/null +++ b/anakamura/src/C114.java @@ -0,0 +1,57 @@ +package anakamura.src; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class C114 { + public static void main(String[] args) { + final var sc = new Scanner(System.in); + + // 一番初めの文字取得 + final int N = sc.nextInt(); + sc.nextLine(); + // Listを作成し、すべての文字列を取得 + List words = new ArrayList<>(); + for (int i = 0; i < N; i++) { + words.add(sc.nextLine()); + } + sc.close(); + + C114 checkKeywords = new C114(); + checkKeywords.wordsCheckMethod(words); + } + + public void wordsCheckMethod(List words) { + // 初めの単語の末尾と次の単語の先頭の文字が等しいかを順番に調べる + for (int i = 0; i < 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 { + final StringBuilder sb = new StringBuilder(); + sb.append(char1).append(" ").append(char2); + final String result = sb.toString(); + System.out.println(result); + break; + } + + } + } + +} -- GitLab From 07f180258f1146a8ffc11fc26f1b887be9c2e68b Mon Sep 17 00:00:00 2001 From: anakamura Date: Mon, 7 Jul 2025 14:46:37 +0900 Subject: [PATCH 2/3] =?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 From 0971a3cf18c84e8ed3c1f537a1cc95f4427d4bb2 Mon Sep 17 00:00:00 2001 From: anakamura Date: Tue, 8 Jul 2025 14:55:33 +0900 Subject: [PATCH 3/3] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CC114?= =?UTF-8?q?=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/C114.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/anakamura/src/C114.java b/anakamura/src/C114.java index 271cfea..0f0b6cb 100644 --- a/anakamura/src/C114.java +++ b/anakamura/src/C114.java @@ -17,30 +17,25 @@ public class C114 { words.add(sc.nextLine()); } sc.close(); - System.out.println(wordsCheckMethod(words)); } public static String wordsCheckMethod(final List words) { - - // 初めの単語の末尾と次の単語の先頭の文字が等しいかを順番に調べる - for (int i = 0; i + 1 > words.size(); i++) { + for (int i = 0; i < words.size() - 1; i++) { final String currentword = words.get(i); // 初めの単語の末尾を取得 final char char1 = (currentword.charAt(currentword.length() - 1)); // 次の単語の先頭の文字を取得 final char char2 = (words.get(i + 1).charAt(0)); - // char1とchar2が等しくない場合、こちらを出力 if (char1 != char2) { final StringBuilder sb = new StringBuilder(); sb.append(char1).append(" ").append(char2); - final String result = sb.toString(); return sb.toString(); } - - } // すべて等しいときは、こちらを出力 + } + // すべて等しいときは、こちらを出力 return "Yes"; } -- GitLab