結果

問題 No.39 桁の数字を入れ替え
ユーザー kou6839kou6839
提出日時 2014-11-18 17:25:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 161 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 85,756 KB
実行使用メモリ 55,312 KB
最終ジャッジ日時 2024-04-10 04:29:32
合計ジャッジ時間 5,732 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
53,976 KB
testcase_01 AC 159 ms
54,916 KB
testcase_02 AC 113 ms
53,116 KB
testcase_03 AC 161 ms
55,148 KB
testcase_04 AC 160 ms
55,192 KB
testcase_05 AC 151 ms
54,788 KB
testcase_06 AC 153 ms
54,900 KB
testcase_07 AC 154 ms
55,108 KB
testcase_08 AC 126 ms
53,872 KB
testcase_09 AC 124 ms
54,120 KB
testcase_10 AC 153 ms
55,136 KB
testcase_11 AC 155 ms
55,012 KB
testcase_12 AC 153 ms
55,036 KB
testcase_13 AC 153 ms
54,984 KB
testcase_14 AC 153 ms
55,312 KB
testcase_15 AC 152 ms
55,152 KB
testcase_16 AC 153 ms
55,132 KB
testcase_17 AC 161 ms
55,012 KB
testcase_18 AC 155 ms
55,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		String num = n+"";
		for(int i=0;i<num.length()-1;i++){
			int max=num.charAt(i);
			int basyo=i;
			for(int j=i+1;j<num.length();j++){
				if(max<=num.charAt(j)&num.charAt(j)!=num.charAt(i)){
					basyo=j;
					max=num.charAt(j);
				}
			}
			if(basyo!=i){
				char[] sss = num.toCharArray();
				char temp = sss[i];
				sss[i]=sss[basyo];
				sss[basyo]=temp;
				String ans="";
				for(int k=0;k<num.length();k++){
					ans+=sss[k];
				}
				System.out.println(ans);
				return;
			}
			
		}
		System.out.println(n);

	}
}	
0