結果

問題 No.927 Second Permutation
ユーザー poi_kyopro
提出日時 2019-11-22 21:32:44
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 874 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 74,568 KB
実行使用メモリ 58,860 KB
最終ジャッジ日時 2024-10-11 02:54:58
合計ジャッジ時間 8,320 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 16
権限があれば一括ダウンロードができます

ソースコード

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 = 2; i < x.length(); i++){
            if(copy[1] != copy[i]){
                int tmp = copy[1];
                copy[1] = copy[i];
                copy[i] = (char)tmp;
                flag = true;
                break;
            }
        }
        
        if(flag){
            System.out.println(copy);
        }else{
            System.out.println(-1);
        }
        
    }
}
0