結果

問題 No.39 桁の数字を入れ替え
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-25 00:39:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 898 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 77,888 KB
実行使用メモリ 41,352 KB
最終ジャッジ日時 2024-04-24 10:19:47
合計ジャッジ時間 4,723 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
41,060 KB
testcase_01 AC 105 ms
40,972 KB
testcase_02 AC 107 ms
41,024 KB
testcase_03 AC 111 ms
41,112 KB
testcase_04 AC 97 ms
39,344 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 103 ms
40,492 KB
testcase_09 AC 109 ms
41,352 KB
testcase_10 AC 109 ms
40,808 KB
testcase_11 WA -
testcase_12 AC 109 ms
41,056 KB
testcase_13 AC 104 ms
40,380 KB
testcase_14 AC 114 ms
41,260 KB
testcase_15 AC 97 ms
39,684 KB
testcase_16 AC 107 ms
40,960 KB
testcase_17 AC 106 ms
40,804 KB
testcase_18 AC 101 ms
40,548 KB
権限があれば一括ダウンロードができます

ソースコード

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;
		for (int i=0; i<s.length()-1; i++) {
			base = Integer.parseInt(s.substring(i,i+1));
			int max = -1;
			int l = 0;
			int r = 0;
			for (int j=s.length()-1; j>=i+1; j--) {
				search = Integer.parseInt(s.substring(j,j+1));
				if (search > base) {
					max = Math.max(max,search);
					l = i;
					r = j;
				}
			}
			if (max > base) {swap(ar,l,r); break;}
		}
		
		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