結果

問題 No.39 桁の数字を入れ替え
ユーザー Tsukasa_Type
提出日時 2018-02-25 00:37:14
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 785 bytes
コンパイル時間 2,801 ms
コンパイル使用メモリ 84,712 KB
実行使用メモリ 41,608 KB
最終ジャッジ日時 2024-11-06 17:51:06
合計ジャッジ時間 5,573 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 6
権限があれば一括ダウンロードができます

ソースコード

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