結果

問題 No.39 桁の数字を入れ替え
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-18 15:13:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,233 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 85,472 KB
実行使用メモリ 42,756 KB
最終ジャッジ日時 2024-04-24 02:43:30
合計ジャッジ時間 6,574 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
42,436 KB
testcase_01 AC 168 ms
42,364 KB
testcase_02 AC 165 ms
42,428 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 164 ms
42,424 KB
testcase_08 AC 161 ms
42,444 KB
testcase_09 AC 165 ms
42,468 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 151 ms
41,928 KB
testcase_15 AC 166 ms
42,408 KB
testcase_16 AC 169 ms
42,392 KB
testcase_17 AC 169 ms
42,416 KB
testcase_18 AC 164 ms
42,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n=scanner.nextInt();
		Map<Integer,Integer>map=new TreeMap<>();
		int key=1;
		int tmpKey=0;
		int tmpVal=0;
		for(int i=n;i>0;i/=10) {
			tmpKey=key;
			tmpVal=i%10;
			map.put(key, i%10);
			key++;
		}
		List<Entry<Integer, Integer>> entryList = new ArrayList<Entry<Integer, Integer>>(map.entrySet());
        Collections.sort(entryList, new Comparator<Entry<Integer, Integer>>() {
            public int compare(Entry<Integer, Integer> obj1, Entry<Integer, Integer> obj2) {
                return obj2.getValue().compareTo(obj1.getValue());
            }
        });
        int tmpKey1=entryList.get(0).getKey();
        int tmpVal1=entryList.get(0).getValue();
        map.put(tmpKey1, tmpVal);
        map.put(tmpKey, tmpVal1);
        String ans="";
        for(int v:map.values()) {
        	ans=v+ans;
        }
        System.out.println(Integer.parseInt(ans));
	}
}
0