結果

問題 No.39 桁の数字を入れ替え
ユーザー holegumaholeguma
提出日時 2015-08-11 01:20:27
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 870 bytes
コンパイル時間 2,159 ms
コンパイル使用メモリ 74,192 KB
実行使用メモリ 51,752 KB
最終ジャッジ日時 2023-09-25 08:02:21
合計ジャッジ時間 3,748 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,396 KB
testcase_01 AC 43 ms
49,656 KB
testcase_02 AC 43 ms
49,156 KB
testcase_03 AC 43 ms
49,360 KB
testcase_04 AC 43 ms
49,360 KB
testcase_05 AC 43 ms
49,164 KB
testcase_06 AC 44 ms
49,228 KB
testcase_07 AC 43 ms
47,300 KB
testcase_08 WA -
testcase_09 AC 44 ms
49,148 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 43 ms
47,364 KB
testcase_15 AC 42 ms
49,400 KB
testcase_16 AC 43 ms
49,376 KB
testcase_17 AC 43 ms
49,620 KB
testcase_18 AC 48 ms
49,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;

class Main{

static final PrintWriter out=new PrintWriter(System.out);

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
char[] num=line.toCharArray();
boolean[] used=new boolean[10];
for(int i=0;i<num.length;i++){
used[(int)(num[i]-'0')]=true;
}
loop:
for(int i=9;i>=1;i--){
if(!used[i]) continue;
for(int j=0;j<num.length;j++){
if((int)(num[j]-'0')>=i) continue;
swap(j,rightNum(i,num),num);
break loop;
}
}
out.println(num);
out.flush();
}
}

private static void swap(int a,int b,char[] num){
char c=num[a];
num[a]=num[b];
num[b]=c;
}

private static int rightNum(int a,char[] num){
for(int i=num.length-1;i>=0;i--){
if((int)(num[i]-'0')==a) return i;
}
return -1;
}
}
0