結果
問題 | No.39 桁の数字を入れ替え |
ユーザー |
|
提出日時 | 2018-03-20 23:31:54 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 128 ms / 5,000 ms |
コード長 | 1,575 bytes |
コンパイル時間 | 3,560 ms |
コンパイル使用メモリ | 79,968 KB |
実行使用メモリ | 41,568 KB |
最終ジャッジ日時 | 2024-06-24 17:54:04 |
合計ジャッジ時間 | 6,933 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.Scanner; import java.util.Set; import java.util.Collections; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(1, in, out); out.close(); } static class Task { public void solve(int testNumber, Scanner in, PrintWriter out) { String s = in.next(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length() - 1; i++) { Set<Character> cs = new HashSet<>(); for (int j = i + 1; j < s.length(); j++) cs.add(s.charAt(j)); char tc = Collections.max(cs); char ic = s.charAt(i); if (tc > ic) { int index = s.lastIndexOf(tc); sb.append(s.substring(0, i)); sb.append(tc); sb.append(s.substring(i + 1, index)); sb.append(ic); sb.append(s.substring(index + 1, s.length())); out.println(sb); return; } } out.println(s); } } }