結果

問題 No.927 Second Permutation
ユーザー poi_kyopropoi_kyopro
提出日時 2019-11-23 00:07:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 917 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 74,840 KB
実行使用メモリ 43,192 KB
最終ジャッジ日時 2024-04-19 14:05:18
合計ジャッジ時間 7,215 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
41,408 KB
testcase_01 AC 102 ms
41,232 KB
testcase_02 AC 105 ms
41,568 KB
testcase_03 AC 108 ms
41,640 KB
testcase_04 AC 108 ms
41,316 KB
testcase_05 AC 103 ms
41,456 KB
testcase_06 AC 95 ms
41,696 KB
testcase_07 AC 105 ms
41,600 KB
testcase_08 AC 123 ms
42,180 KB
testcase_09 AC 102 ms
41,620 KB
testcase_10 AC 161 ms
42,392 KB
testcase_11 AC 182 ms
42,972 KB
testcase_12 AC 142 ms
42,448 KB
testcase_13 AC 131 ms
42,072 KB
testcase_14 AC 164 ms
42,200 KB
testcase_15 AC 138 ms
42,480 KB
testcase_16 AC 187 ms
43,108 KB
testcase_17 AC 180 ms
43,124 KB
testcase_18 AC 186 ms
42,816 KB
testcase_19 AC 181 ms
43,004 KB
testcase_20 AC 181 ms
42,980 KB
testcase_21 AC 182 ms
42,972 KB
testcase_22 AC 184 ms
43,192 KB
testcase_23 AC 185 ms
42,540 KB
testcase_24 AC 187 ms
42,824 KB
testcase_25 AC 168 ms
42,104 KB
testcase_26 AC 164 ms
42,688 KB
testcase_27 AC 144 ms
42,652 KB
testcase_28 AC 173 ms
42,940 KB
testcase_29 AC 172 ms
42,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        String x = stdIn.next();
        char c[] = x.toCharArray();
        char copy[] = new char[x.length()];
        
        Arrays.sort(c);
        
        for(int i = 0; i < x.length(); i++){
            copy[i] = c[x.length() - i - 1];
        }
        
        boolean flag = false;
        
        for(int i = x.length() - 2; i >= 0; i--){
            if(copy[x.length() - 1] != copy[i]){
                int tmp = copy[i + 1];
                copy[i + 1] = copy[i];
                copy[i] = (char)tmp;
                flag = true;
                break;
            }
        }
        
        if(flag && copy[0] != '0'){
            System.out.println(copy);
        }else{
            System.out.println(-1);
        }
        
    }
}
0