結果
| 問題 | No.39 桁の数字を入れ替え | 
| コンテスト | |
| ユーザー |  holeguma | 
| 提出日時 | 2015-08-11 01:22:25 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 55 ms / 5,000 ms | 
| コード長 | 870 bytes | 
| コンパイル時間 | 2,306 ms | 
| コンパイル使用メモリ | 76,688 KB | 
| 実行使用メモリ | 37,376 KB | 
| 最終ジャッジ日時 | 2024-10-02 06:39:30 | 
| 合計ジャッジ時間 | 3,778 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
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;
int l=rightNum(i,num);
for(int j=0;j<l;j++){
if((int)(num[j]-'0')>=i) continue;
swap(j,l,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;
}
}
            
            
            
        