結果

問題 No.39 桁の数字を入れ替え
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-25 00:37:14
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 785 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 76,768 KB
実行使用メモリ 41,436 KB
最終ジャッジ日時 2024-04-24 10:16:50
合計ジャッジ時間 4,624 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
39,496 KB
testcase_01 AC 112 ms
41,076 KB
testcase_02 AC 108 ms
41,436 KB
testcase_03 AC 104 ms
40,264 KB
testcase_04 AC 109 ms
41,224 KB
testcase_05 AC 98 ms
40,124 KB
testcase_06 AC 106 ms
41,060 KB
testcase_07 AC 106 ms
40,076 KB
testcase_08 AC 111 ms
41,196 KB
testcase_09 AC 108 ms
41,324 KB
testcase_10 AC 106 ms
40,136 KB
testcase_11 AC 107 ms
41,132 KB
testcase_12 WA -
testcase_13 AC 101 ms
40,336 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		String s = sc.next();
		
		int[] ar = new int[s.length()];
		for (int i=0; i<s.length(); i++) {
			ar[i] = Integer.parseInt(s.substring(i,i+1));
		}
		
		int base = 0;
		int search = 0;
		
		loop:
		for (int i=0; i<s.length()-1; i++) {
			base = Integer.parseInt(s.substring(i,i+1));
			for (int j=s.length()-1; j>=i+1; j--) {
				search = Integer.parseInt(s.substring(j,j+1));
				if (search > base) {swap(ar,i,j); break loop;}
			}
		}
		
		for (int i=0; i<s.length(); i++) {
			System.out.print(ar[i]);
		}
		System.out.println();
	}
	
	static int[] swap (int[] ar, int a, int b) {
		int temp = ar[a];
		ar[a] = ar[b];
		ar[b] = temp;
		return ar;
	}
}
0