結果
問題 |
No.39 桁の数字を入れ替え
|
ユーザー |
![]() |
提出日時 | 2015-08-11 01:20:27 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 870 bytes |
コンパイル時間 | 2,075 ms |
コンパイル使用メモリ | 77,924 KB |
実行使用メモリ | 50,588 KB |
最終ジャッジ日時 | 2024-07-18 06:36:57 |
合計ジャッジ時間 | 3,356 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 5 |
ソースコード
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; } }