結果

問題 No.52 よくある文字列の問題
ユーザー YamaKasaYamaKasa
提出日時 2018-06-24 20:08:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,029 bytes
コンパイル時間 3,936 ms
コンパイル使用メモリ 79,640 KB
実行使用メモリ 56,752 KB
最終ジャッジ日時 2023-09-13 13:46:23
合計ジャッジ時間 6,505 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
56,080 KB
testcase_01 AC 114 ms
55,740 KB
testcase_02 AC 116 ms
55,460 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 116 ms
55,956 KB
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();
		String []s = S.split("");
		Set<String> set = new HashSet<String>();
		String []t = new String[s.length];
		String s0 = s[0];
		for(int i = 0; i < s.length; i++) {
			for(int j = 0; j < s.length; j++) {
				if(i < j) {
					t[j] = s[j - 1];
				}else if(i == j) {
					t[j] = s0;
				}else {
					t[j] = s[j];
				}
			}
			set.add(con(t));
		}
		String sn = s[s.length - 1];
		for(int i = 0; i < s.length; i++) {
			for(int j = 0; j < s.length; j++) {
				if(i < j) {
					t[j] = s[j];
				}else if(i == j) {
					t[j] = sn;
				}else {
					t[j] = s[j + 1];
				}
			}
			set.add(con(t));
		}
		System.out.println(set.size());


	}
	public static String con(String[] s) {
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < s.length; i++) {
			sb.append(s[i]);
		}
		return sb.toString();
	}

}
0